CSES - Datatähti 2021 alku - Results
Submission details
Task:Alitaulukot
Sender:T
Submission time:2020-09-30 20:03:09 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp:38:5: error: 'int index' redeclared as different kind of symbol
 int index = 1;
     ^~~~~
In file included from /usr/include/string.h:431:0,
                 from /usr/include/c++/7/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:48,
                 from input/code.cpp:7:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
 index (const char *__s, int __c) __THROW
 ^~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:57:81: error: overloaded function with no contextual type information
             index = min(maximumQ.front().second + 1, minimumQ.front().second + 1);
                                                                                 ^
input/code.cpp:58:65: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<'
             while (!minimumQ.empty() && minimumQ.front().second < index) {...

Code

/**
* Datat�hti 2021 alku
* Alitaulukot/Subtables
* @author TRS
*/
//Include
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <list>
#include <queue>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <regex>
#include <iterator>
//Definitions
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<pii> vpii;
#define pb push_back
#define mp make_pair
#define mt make_tuple
//Constants
#define infinity 0x3f3f3f3f
#define linfinity 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
const int MX = 100001;
int n, k;
int a[MX];
ll answer = 0;
int index = 1;
deque<pii> minimumQ, maximumQ;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
for (int i = 1; i <= n; i++) {
cin>>a[i];
}
for (int i = 1; i <= n; i++) {
while (!minimumQ.empty() && minimumQ.back().first >= a[i]) {
minimumQ.pop_back();
}
minimumQ.pb({a[i], i});
while (!maximumQ.empty() && maximumQ.back().first <= a[i]) {
maximumQ.pop_back();
}
maximumQ.pb({a[i], i});
while (!minimumQ.empty() && !maximumQ.empty() && maximumQ.front().first - minimumQ.front().first > k) {
index = min(maximumQ.front().second + 1, minimumQ.front().second + 1);
while (!minimumQ.empty() && minimumQ.front().second < index) {
minimumQ.pop_front();
}
while (!maximumQ.empty() && maximumQ.front().second < index) {
maximumQ.pop_front();
}
}
answer += i - index + 1;
}
cout<<answer<<"\n";
return 0;
}