//gm --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NET r < tl || tr < l
#define double long double
using namespace std;
const int N=3e5+7;
const int M=1e9+7;
const int inf=1e9;
int n, m, k, x;
int b[N];
struct qu{
int l, r, p;
}f[N];
int l[N];
int r[N];
vector <int> q[N], pos[N];
int p[N*4];
void push(int v, int tl, int tr){
if(!p[v] || tl == tr)return;
p[v+v] += p[v];
p[v+v+1] += p[v];
p[v] = 0;
}
void build(int v=1, int tl=1, int tr=m){
p[v] = 0;
if(tl == tr)return;
build(TL);
build(TR);
}
void upd(int l, int r, int x, int v=1, int tl=1, int tr=m){
if(NET)return;
if(DA){
p[v] += x;
return;
}
upd(l, r, x, TL);
upd(l, r, x, TR);
}
int get(int pos, int v=1, int tl=1, int tr=m){
push(v, tl, tr);
if(tl == tr)return p[v];
if(pos <= tm)return get(pos, TL);
else return get(pos, TR);
}
void AlemAmenov(){
cin >> n >> m;
for(int i=1; i <= m; i++){
cin >> x;
pos[x].pb(i);
}
for(int i=1; i <= n; i++){
cin >> b[i];
}
cin >> k;
for(int i=1; i <= k; i++){
cin >> f[i].l >> f[i].r >> f[i].p;
}
for(int i=1; i <= n; i++){
l[i] = 1;
r[i] = k;
}
for(int gg=1; gg <= 20; gg++){
build();
for(int i=1; i <= k; i++){
q[i].clear();
}
for(int i=1; i <= n; i++){
if(l[i] <= r[i]){
int md = (l[i] + r[i])/2;
q[md].pb(i);
}
}
for(int i=1; i <= k; i++){
if(f[i].l <= f[i].r){
upd(f[i].l, f[i].r, f[i].p);
}
else {
upd(1, f[i].r, f[i].p);
upd(f[i].l, m, f[i].p);
}
for(int j : q[i]){
int sum=0;
for(int it : pos[j]){
sum += get(it);
if(b[j] <= sum)break;
}
if(sum < b[j])l[j] = i+1;
else r[j] = i-1;
}
}
}
for(int i=1; i <= n; i++){
if(l[i] <= k)cout << l[i] << '\n';
else cout << "NIE\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
int RealName=1;
// cin >> RealName;
// int C=0;
while(RealName--){
// cout << "Case " << ++C << ":\n";
AlemAmenov();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
22872 KB |
Output is correct |
2 |
Correct |
8 ms |
23128 KB |
Output is correct |
3 |
Correct |
11 ms |
22876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
23132 KB |
Output is correct |
2 |
Correct |
10 ms |
22876 KB |
Output is correct |
3 |
Correct |
9 ms |
23132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
29428 KB |
Output is correct |
2 |
Correct |
373 ms |
32644 KB |
Output is correct |
3 |
Correct |
358 ms |
31740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
324 ms |
31056 KB |
Output is correct |
2 |
Correct |
349 ms |
30860 KB |
Output is correct |
3 |
Correct |
344 ms |
32996 KB |
Output is correct |
4 |
Correct |
73 ms |
28252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
29780 KB |
Output is correct |
2 |
Correct |
214 ms |
33040 KB |
Output is correct |
3 |
Correct |
157 ms |
25792 KB |
Output is correct |
4 |
Correct |
338 ms |
32196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
28844 KB |
Output is correct |
2 |
Correct |
279 ms |
31180 KB |
Output is correct |
3 |
Correct |
299 ms |
29264 KB |
Output is correct |
4 |
Correct |
344 ms |
34352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2709 ms |
65536 KB |
Output is correct |
2 |
Correct |
906 ms |
47704 KB |
Output is correct |
3 |
Correct |
730 ms |
31600 KB |
Output is correct |
4 |
Runtime error |
1889 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2721 ms |
65044 KB |
Output is correct |
2 |
Correct |
815 ms |
46484 KB |
Output is correct |
3 |
Correct |
586 ms |
31060 KB |
Output is correct |
4 |
Runtime error |
1480 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |