#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pi pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
struct Fenwick{
vector<int> t;
int n;
Fenwick(int n): n(n){
t.resize(n+1);
}
void add(int v){
while(v>0){
t[v]++;
v -= v&-v;
}
}
int get(int v){
int res = 0;
while(v <= n){
res += t[v];
v += v&-v;
}
return res;
}
};
void op(vector<int> &a, vector<int> &A, vector<int> &B){
if(a.size() <= 1){
A = a;
B.pb(0);
return;
}
A.pb(a[0]);
A.pb(a[1]);
B.pb(0);
B.pb(1);
for(int i = 2; i < a.size(); ++i){
if(a[i] > A.back() && A.back() > A[int(A.size()) - 2]){
A.pop_back();
B.pop_back();
A.pb(a[i]);
B.pb(i);
}else if(a[i] < A.back() && A.back() < A[int(A.size()) - 2]){
A.pop_back();
B.pop_back();
A.pb(a[i]);
B.pb(i);
}else{
A.pb(a[i]);
B.pb(i);
}
}
}
int n;
vector<int> A, B, A2, A1, B1, B2, a;
Fenwick f(1000000);
void init(int nn, std::vector<int> aa) { n=nn;a=aa;
if(n == 1) return;
op(a, A, B);
// elimizde a b var cool
if(A[0] > A[1]){
for(int i = 0; i < A.size(); i += 2){
f.add(B[i]);
}
}else{
for(int i = 1; i < A.size(); i += 2){
f.add(B[i]);
}
}
}
int max_towers(int L, int R, int D) {
if(n == 1 || L == R) return 1;
return max(f.get(R-1) - f.get(L), 2);
}
Compilation message
towers.cpp: In function 'void op(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
towers.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 2; i < a.size(); ++i){
| ~~^~~~~~~~~~
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < A.size(); i += 2){
| ~~^~~~~~~~~~
towers.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 1; i < A.size(); i += 2){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
245 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4184 KB |
1st lines differ - on the 1st token, expected: '13', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4184 KB |
1st lines differ - on the 1st token, expected: '13', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
421 ms |
6356 KB |
1st lines differ - on the 1st token, expected: '11903', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4072 ms |
4696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4184 KB |
1st lines differ - on the 1st token, expected: '13', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
245 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |