#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
int n,m,q;
int bl[N],need[N];
vector<int> wh[N];
int l[N],r[N];
vector<int> ask[N];
vector<tuple<int,int,int> > inp;
long long fw[N];
void update(int idx,long long val){ while(idx<N) fw[idx]+=val,idx+=(idx & -idx); }
long long read(int idx){ if(idx==0) return 0; long long val = 0; while(idx>0) val+=fw[idx],idx-=(idx & -idx); return val; }
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= m;i++) cin >> bl[i],wh[bl[i]].push_back(i);
for(int i = 1;i <= n;i++) cin >> need[i];
cin >> q;
for(int i = 1;i <= q;i++)
{
int l,r,k;
cin >> l >> r >> k;
inp.push_back({l,r,k});
}
for(int i = 1;i <= n;i++) l[i] = 1,r[i] = q+1;
while(true)
{
bool done = true;
for(int i = 1;i <= n;i++) if(l[i]<r[i]) done = false,ask[(l[i]+r[i])/2].push_back(i);
if(done) break;
for(int i = 1;i <= m;i++) fw[i] = 0;
for(int i = 1;i <= q;i++)
{
auto [ll,rr,k] = inp[i-1];
if(ll<=rr) update(ll,k),update(rr+1,-k);
else update(1,k),update(rr+1,-k),update(ll,k);
for(int x : ask[i])
{
long long tmp = 0;
for(int y : wh[x]){ tmp+=read(y); if(tmp>1e9) tmp = 1e9 + 1; }
if(tmp>=need[x]) r[x] = i;
else l[x] = i+1;
}
ask[i].clear();
}
}
for(int i = 1;i <= n;i++) if(l[i]<=q) cout << l[i] << '\n'; else cout << "NIE\n";
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:41:18: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [ll,rr,k] = inp[i-1];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
25088 KB |
Output is correct |
2 |
Correct |
19 ms |
25088 KB |
Output is correct |
3 |
Correct |
17 ms |
25088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
25088 KB |
Output is correct |
2 |
Correct |
17 ms |
25088 KB |
Output is correct |
3 |
Correct |
20 ms |
25088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
27120 KB |
Output is correct |
2 |
Correct |
164 ms |
28960 KB |
Output is correct |
3 |
Correct |
145 ms |
28764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
28136 KB |
Output is correct |
2 |
Correct |
141 ms |
28140 KB |
Output is correct |
3 |
Correct |
163 ms |
29164 KB |
Output is correct |
4 |
Correct |
50 ms |
27384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
27516 KB |
Output is correct |
2 |
Correct |
186 ms |
29680 KB |
Output is correct |
3 |
Correct |
123 ms |
25980 KB |
Output is correct |
4 |
Correct |
139 ms |
29012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
26656 KB |
Output is correct |
2 |
Correct |
168 ms |
28128 KB |
Output is correct |
3 |
Correct |
105 ms |
26988 KB |
Output is correct |
4 |
Correct |
161 ms |
30320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1154 ms |
45784 KB |
Output is correct |
2 |
Correct |
1265 ms |
34020 KB |
Output is correct |
3 |
Correct |
684 ms |
30568 KB |
Output is correct |
4 |
Correct |
2056 ms |
65536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1163 ms |
44868 KB |
Output is correct |
2 |
Correct |
742 ms |
34016 KB |
Output is correct |
3 |
Correct |
531 ms |
31164 KB |
Output is correct |
4 |
Runtime error |
1970 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |