#include<iostream>
#include<random>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN = 1e6 + 5;
mt19937 rnd(69420);
int n;
int a[MAXN];
int findIndex(vector <int> &v, int x)
{
if(v[0]>=x) return -1;
int l = 0, r = v.size() - 1, mid;
while(l+1<r)
{
mid = (l+r)/2;
if(v[mid]<x) l = mid;
else r = mid - 1;
}
if(v[r]<x) return v[r];
return v[l];
}
struct node
{
int maxCost;
vector <int> v;
int l, r;
node *L, *R;
node(){}
node(int l, int r)
{
this->l = l;
this->r = r;
this->maxCost = 0;
this->v = vector <int>{};
this->L = nullptr;
this->R = nullptr;
}
int calcCost(node *A, node *B)
{
int ans = max(A->maxCost, B->maxCost);
int x = findIndex(B->v, A->v.back());
if(x!=-1) ans = max(ans, x + A->v.back());
return ans;
}
void build()
{
if(this->l==this->r)
{
this->v = vector <int>{a[this->l]};
return;
}
this->L = new node(this->l, (this->l+this->r)/2);
this->R = new node((this->l+this->r)/2+1, this->r);
this->L->build();
this->R->build();
this->maxCost = this->calcCost(this->L, this->R);
for(int x: this->L->v) this->v.push_back(x);
for(int x: this->R->v) this->v.push_back(x);
sort(this->v.begin(), this->v.end());
}
void query(int ql, int qr, vector <node*> &output)
{
if(this->l>=ql && this->r<=qr)
{
output.push_back(this);
return;
}
if(this->r<ql || this->l>qr) return;
this->L->query(ql, qr, output);
this->R->query(ql, qr, output);
}
};
node *T;
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(NULL);
int Q;
n = 1000000;
//Q = 1000000;
//cin >> n >> Q;
for(int i = 0;i<n;i++)
{
//cin >> a[i];
a[i] = rnd();
}
T = new node(0, n-1);
T->build();
return 0;
vector <node*> v;
while(Q--)
{
int l, r, x;
cin >> l >> r >> x;
l--;r--;
int cost = 0;
v.clear();T->query(l, r, v);
int maxElement = -1;
for(int i = 0;i<v.size();i++)
{
cost = max(cost, v[i]->maxCost);
if(maxElement!=-1)
{
int curr = findIndex(v[i]->v, maxElement);
if(curr!=-1) cost = max(cost, curr + maxElement);
}
maxElement = max(maxElement, v[i]->v.back());
}
if(cost<=x) cout << "1" << '\n';
else cout << "0" << '\n';
}
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:130:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<v.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1457 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1457 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1448 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1490 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1457 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1457 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |