#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
using namespace std;
using ll = long long;
const ll N = 3e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
ll p[N] , n , m , k , L[N] , R[N] , res[N];
ll t[N*4];
ll l[N] , r[N] , c[N];
vector<ll> g[N] , q[N] , q1[N];
void build(ll v , ll tl , ll tr){
t[v] = 0;
if(tl == tr) return;
ll tm = (tl+tr) >> 1;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
}
void upd(ll v, ll tl , ll tr , ll l , ll r , ll val){
if(l <= tl && tr <= r){
t[v] += val;
return;
}
if(tl > r || tr < l) return;
ll tm = (tl+tr) >> 1;
upd(v*2,tl,tm,l,r,val);
upd(v*2+1,tm+1,tr,l,r,val);
}
ll get(ll v, ll tl , ll tr , ll pos){
if(tl == tr) return t[v];
ll 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(ll i = 1; i <= m; i++) {
ll a;
cin >> a;
g[a].push_back(i);
}
for(ll i = 1; i <= n; i++) cin >> p[i];
cin >> k;
for(ll i = 1; i <= n; i++) {
L[i] = 1;
R[i] = k;
q[(L[i]+R[i])/2].push_back(i);
}
for(ll i = 1; i <= k; i++) cin >> l[i] >> r[i] >> c[i];
ll ok = 1;
while(ok){
ok = 0;
build(1,1,m);
for(ll 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(ll x : q[i]){
ll sum = p[x];
for(ll 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]){
q1[(L[x]+R[x])/2].push_back(x);
ok++;
}
}
q[i].clear();
}
swap(q,q1);
}
for(ll i = 1; i <= n; i++) {
if(res[i] == 0){
cout << "NIE\n";
} else {
cout << res[i] << "\n";
}
}
}
/*
*/
signed main(){
ios;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
21548 KB |
Output is correct |
2 |
Correct |
21 ms |
21628 KB |
Output is correct |
3 |
Correct |
20 ms |
21548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
21740 KB |
Output is correct |
2 |
Correct |
22 ms |
21588 KB |
Output is correct |
3 |
Correct |
22 ms |
21696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
278 ms |
25124 KB |
Output is correct |
2 |
Correct |
348 ms |
28640 KB |
Output is correct |
3 |
Correct |
340 ms |
27444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
318 ms |
26652 KB |
Output is correct |
2 |
Correct |
333 ms |
26676 KB |
Output is correct |
3 |
Correct |
361 ms |
29020 KB |
Output is correct |
4 |
Correct |
87 ms |
25804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
25672 KB |
Output is correct |
2 |
Correct |
220 ms |
29224 KB |
Output is correct |
3 |
Correct |
141 ms |
22844 KB |
Output is correct |
4 |
Correct |
323 ms |
28112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
24320 KB |
Output is correct |
2 |
Correct |
333 ms |
26616 KB |
Output is correct |
3 |
Correct |
294 ms |
24764 KB |
Output is correct |
4 |
Correct |
367 ms |
30280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2806 ms |
61644 KB |
Output is correct |
2 |
Incorrect |
1402 ms |
39612 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2876 ms |
59540 KB |
Output is correct |
2 |
Incorrect |
1048 ms |
39524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |