#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=300001;
int n,m,q,o[N],p[N],l[N],r[N],a[N],up[N],lo[N],ans[N];
ll tot[N];
VI qv[N],qs[N];
struct ds {
ll c[N];
ds() {
rep(i,0,N) c[i]=0;
}
void modify(int x,int y) {
for (;x<N;x+=x&-x) c[x]+=y;
}
ll query(int x) {
ll s=0;
for (;x;x-=x&-x) s+=c[x];
return s;
}
};
signed main() {
scanf("%lld%lld",&n,&m);
rep(i,1,m+1) scanf("%lld",o+i),qv[o[i]].pb(i);
rep(i,1,n+1) scanf("%lld",p+i);
scanf("%lld",&q);
rep(i,1,q+1) scanf("%lld%lld%lld",l+i,r+i,a+i);
rep(i,1,n+1) lo[i]=1,up[i]=q,ans[i]=q+1;
rep(it,0,50) {
rep(i,1,n+1) tot[i]=0;
rep(i,1,q+1) qs[i].clear();
rep(i,1,n+1) if (lo[i]<=up[i])
qs[(lo[i]+up[i])/2].pb(i);
ds fenw;
rep(i,1,q+1) {
if (l[i]<=r[i]) {
fenw.modify(l[i],a[i]);
fenw.modify(r[i]+1,-a[i]);
} else {
fenw.modify(l[i],a[i]);
fenw.modify(1,a[i]);
fenw.modify(r[i]+1,-a[i]);
}
for (auto x:qs[i]) for (auto y:qv[x]) if (tot[x]<p[x])
tot[x]+=fenw.query(y);
}
rep(i,1,n+1) {
if (lo[i]>up[i]) continue;
int md=(lo[i]+up[i])/2;
if (tot[i]>=p[i]) ans[i]=md,up[i]=md-1;
else lo[i]=md+1;
}
}
rep(i,1,n+1) {
if (ans[i]>q) puts("NIE");
else printf("%lld\n",ans[i]);
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%lld%lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~
met.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | rep(i,1,m+1) scanf("%lld",o+i),qv[o[i]].pb(i);
| ~~~~~^~~~~~~~~~~~
met.cpp:47:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | rep(i,1,n+1) scanf("%lld",p+i);
| ~~~~~^~~~~~~~~~~~
met.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%lld",&q);
| ~~~~~^~~~~~~~~~~
met.cpp:49:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | rep(i,1,q+1) scanf("%lld%lld%lld",l+i,r+i,a+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
16844 KB |
Output is correct |
2 |
Correct |
17 ms |
16844 KB |
Output is correct |
3 |
Correct |
18 ms |
16900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
16912 KB |
Output is correct |
2 |
Correct |
17 ms |
16844 KB |
Output is correct |
3 |
Correct |
19 ms |
17000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
19932 KB |
Output is correct |
2 |
Correct |
375 ms |
23612 KB |
Output is correct |
3 |
Correct |
203 ms |
22224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
21360 KB |
Output is correct |
2 |
Correct |
276 ms |
21380 KB |
Output is correct |
3 |
Correct |
395 ms |
23788 KB |
Output is correct |
4 |
Correct |
52 ms |
20648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
20364 KB |
Output is correct |
2 |
Correct |
488 ms |
24140 KB |
Output is correct |
3 |
Correct |
293 ms |
18212 KB |
Output is correct |
4 |
Correct |
214 ms |
22884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
19032 KB |
Output is correct |
2 |
Correct |
369 ms |
21360 KB |
Output is correct |
3 |
Correct |
193 ms |
19396 KB |
Output is correct |
4 |
Correct |
290 ms |
25224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2070 ms |
51672 KB |
Output is correct |
2 |
Correct |
1759 ms |
28652 KB |
Output is correct |
3 |
Correct |
1641 ms |
22824 KB |
Output is correct |
4 |
Runtime error |
979 ms |
65540 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1939 ms |
49348 KB |
Output is correct |
2 |
Correct |
1786 ms |
28672 KB |
Output is correct |
3 |
Correct |
1171 ms |
21688 KB |
Output is correct |
4 |
Runtime error |
890 ms |
65540 KB |
Execution killed with signal 9 |