#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
#define int ll
using namespace std;
using ll = long long;
const int N = 3e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int p[N] , n , m , k , L[N] , R[N] , res[N];
ll t[N*4];
int l[N] , r[N] , c[N];
vector<int> g[N] , q[N] , q1[N];
void build(int v , int tl , int tr){
t[v] = 0;
if(tl == tr) return;
int tm = (tl+tr) >> 1;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
}
void upd(int v, int tl , int tr , int l , int r , int val){
if(l <= tl && tr <= r){
t[v] += val;
return;
}
if(tl > r || tr < l) return;
int tm = (tl+tr) >> 1;
upd(v*2,tl,tm,l,r,val);
upd(v*2+1,tm+1,tr,l,r,val);
}
ll get(int v, int tl , int tr , int pos){
if(tl == tr) return t[v];
int tm = (tl+tr) >> 1;
if(tm >= pos) return get(v*2,tl,tm,pos)+t[v];
else return get(v*2+1,tm+1,tr,pos)+t[v];
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int a;
cin >> a;
g[a].push_back(i);
}
for(int i = 1; i <= n; i++) cin >> p[i];
cin >> k;
for(int i = 1; i <= n; i++) {
L[i] = 1;
R[i] = k;
q[(L[i]+R[i])/2].push_back(i);
}
for(int i = 1; i <= k; i++) cin >> l[i] >> r[i] >> c[i];
int ok = 1;
for(int _ = 1; _ <= 20; _++){
build(1,1,m);
for(int i = 1; i <= k; i++){
if(l[i] > r[i]){
upd(1,1,m,l[i],m,c[i]);
upd(1,1,m,1,r[i],c[i]);
} else upd(1,1,m,l[i],r[i],c[i]);
for(int x : q[i]){
ll sum = p[x];
for(int y : g[x]) sum -= get(1,1,m,y);
if(sum <= 0){
res[x] = i;
R[x] = i-1;
} else {
L[x] = i+1;
}
if(L[x] <= R[x]) q[(L[x]+R[x])/2].push_back(x);
}
q[i].clear();
}
}
for(int i = 1; i <= n; i++) {
if(res[i] == 0){
cout << "NIE\n";
} else {
cout << res[i] << "\n";
}
}
}
/*
*/
signed main(){
ios;
solve();
return 0;
}
Compilation message
met.cpp: In function 'void solve()':
met.cpp:58:6: warning: unused variable 'ok' [-Wunused-variable]
58 | int ok = 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
21588 KB |
Output is correct |
2 |
Correct |
16 ms |
21532 KB |
Output is correct |
3 |
Correct |
13 ms |
21588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21588 KB |
Output is correct |
2 |
Correct |
15 ms |
21588 KB |
Output is correct |
3 |
Correct |
17 ms |
21588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
321 ms |
25180 KB |
Output is correct |
2 |
Correct |
378 ms |
28632 KB |
Output is correct |
3 |
Correct |
370 ms |
27408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
354 ms |
26656 KB |
Output is correct |
2 |
Correct |
392 ms |
26624 KB |
Output is correct |
3 |
Correct |
404 ms |
28936 KB |
Output is correct |
4 |
Correct |
103 ms |
25752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
25692 KB |
Output is correct |
2 |
Correct |
252 ms |
29200 KB |
Output is correct |
3 |
Correct |
157 ms |
22844 KB |
Output is correct |
4 |
Correct |
345 ms |
28108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
24320 KB |
Output is correct |
2 |
Correct |
324 ms |
26584 KB |
Output is correct |
3 |
Correct |
349 ms |
25060 KB |
Output is correct |
4 |
Correct |
359 ms |
30256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3421 ms |
61232 KB |
Output is correct |
2 |
Incorrect |
1543 ms |
39300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2877 ms |
59768 KB |
Output is correct |
2 |
Incorrect |
1084 ms |
39780 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |