#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];
long long tree[N << 1],lazy[N << 1];
int l[N],r[N],ans[N];
vector<int> ask[N];
vector<tuple<int,int,int> > inp;
void pushlz(int l,int r,int idx)
{
if(!lazy[idx]) return;
if(l==r) tree[idx]+=lazy[idx];
else lazy[idx*2]+=lazy[idx],lazy[idx*2+1]+=lazy[idx];
lazy[idx] = 0;
}
void build(int l,int r,int idx)
{
tree[idx] = lazy[idx] = 0;
if(l==r) return;
int m = (l+r)/2;
build(l,m,idx*2),build(m+1,r,idx+2+1);
}
void update(int l,int r,int idx,int x,int y,int k)
{
pushlz(l,r,idx);
if(x>r or y<l) return;
if(x<=l and y>=r)
{
lazy[idx]+=k;
pushlz(l,r,idx);
return;
}
int m = (l+r)/2;
update(l,m,idx*2,x,y,k),update(m+1,r,idx*2+1,x,y,k);
}
long long read(int l,int r,int idx,int x)
{
pushlz(l,r,idx);
if(x>r or x<l) return 0;
if(l==r) return tree[idx];
int m = (l+r)/2;
return read(l,m,idx*2,x)+read(m+1,r,idx*2+1,x);
}
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;
build(1,m,1);
for(int i = 1;i <= q;i++)
{
auto [ll,rr,k] = inp[i-1];
if(ll<=rr) update(1,m,1,ll,rr,k);
else update(1,m,1,1,rr,k),update(1,m,1,ll,m,k);
for(int x : ask[i])
{
long long tmp = 0;
for(int y : wh[x]) tmp+=read(1,m,1,y);
int m = (l[x]+r[x])/2;
if(tmp>=need[x]) r[x] = m;
else l[x] = m+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:76:18: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [ll,rr,k] = inp[i-1];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
25088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
25088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
477 ms |
28708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
488 ms |
29244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
234 ms |
28812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
557 ms |
28328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6043 ms |
58744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6003 ms |
57748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |