#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
const int N = 3e5+5;
int n, m, que;
long long t[N<<2];
void U(int l, int r, int val, int v, int tl, int tr){
if(tl > r || tr < l) return;
if(l <= tl && tr <= r){
t[v] += val;
return;
}
int tm = (tl + tr) >> 1;
U(l,r,val,v<<1,tl,tm);
U(l,r,val,v<<1|1,tm+1,tr);
}
long long G(int pos, int v, int l, int r){
if(l == r) return t[v];
int m = (l + r) >> 1;
if(pos <= m) return G(pos,v<<1,l,m) + t[v];
else return G(pos,v<<1|1,m+1,r) + t[v];
}
vector<int> g[N], ans(N, -1), tocheck[N];;
int p[N], Q[N], L[N], R[N];
struct{int l, r, a;}q[N];
signed main(){
NFS;
cin >> n >> m;
for(int i = 1; i <= m; ++i){
int x; cin >> x;
g[x].pb(i);
}
for(int i = 1; i <= n; ++i){
cin >> p[i];
}
cin >> que;
for(int i = 1; i <= que; ++i){
cin >> q[i].l >> q[i].r >> q[i].a;
}
for(int i = 1; i <= n; ++i){
L[i] = 1, R[i] = que+1;
}
bool ok = 1;
while(ok){
ok = false;
memset(t, 0, sizeof(t));
for(int i = 1; i <= n; ++i){
if(L[i] != R[i]){
tocheck[(L[i]+R[i])/2].pb(i);
}
}
for(int i = 1; i <= que; ++i){
if(q[i].l > q[i].r){
U(q[i].l, m, q[i].a, 1, 1, m);
U(1, q[i].r, q[i].a, 1, 1, m);
}else{
U(q[i].l, q[i].r, q[i].a, 1, 1, m);
}
while(!tocheck[i].empty()){
ok = true;
int id = tocheck[i].back();
tocheck[i].pop_back();
long long sum = 0;
for(auto x : g[id]){
sum += G(x, 1, 1, m);
if(sum >= p[id]){
break;
}
}
if(sum >= p[id]){
ans[id] = i;
R[id] = i;
}else L[id] = i + 1;
}
}
}
for(int i = 1; i <= n; ++i){
if(L[i] > que) cout << "NIE\n";
else cout << ans[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
25048 KB |
Output is correct |
2 |
Correct |
26 ms |
25036 KB |
Output is correct |
3 |
Correct |
31 ms |
25036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
25052 KB |
Output is correct |
2 |
Correct |
22 ms |
25044 KB |
Output is correct |
3 |
Correct |
22 ms |
25044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
26352 KB |
Output is correct |
2 |
Correct |
383 ms |
28220 KB |
Output is correct |
3 |
Correct |
365 ms |
27972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
344 ms |
27380 KB |
Output is correct |
2 |
Correct |
333 ms |
27408 KB |
Output is correct |
3 |
Correct |
371 ms |
28452 KB |
Output is correct |
4 |
Correct |
155 ms |
26780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
26792 KB |
Output is correct |
2 |
Correct |
281 ms |
28844 KB |
Output is correct |
3 |
Correct |
197 ms |
25768 KB |
Output is correct |
4 |
Correct |
390 ms |
28380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
25896 KB |
Output is correct |
2 |
Correct |
343 ms |
27772 KB |
Output is correct |
3 |
Correct |
380 ms |
26428 KB |
Output is correct |
4 |
Correct |
441 ms |
29872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3507 ms |
42652 KB |
Output is correct |
2 |
Correct |
1152 ms |
30004 KB |
Output is correct |
3 |
Correct |
753 ms |
28228 KB |
Output is correct |
4 |
Correct |
4266 ms |
63008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3408 ms |
41224 KB |
Output is correct |
2 |
Correct |
834 ms |
30040 KB |
Output is correct |
3 |
Correct |
675 ms |
27652 KB |
Output is correct |
4 |
Correct |
3838 ms |
65536 KB |
Output is correct |