#include <bits/stdc++.h>
using namespace std;
#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=301000;
int n,m,q,o[N],p[N],l[N],r[N],a[N],up[N],lo[N],ok[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;
}
};
int main() {
scanf("%d%d",&n,&m);
rep(i,1,m+1) scanf("%d",o+i),qv[o[i]].pb(i);
rep(i,1,n+1) scanf("%d",p+i);
scanf("%d",&q);
rep(i,1,q+1) scanf("%d%d%d",l+i,r+i,a+i);
rep(i,1,n+1) lo[i]=1,up[i]=q;
rep(it,0,25) {
rep(i,1,n+1) tot[i]=0;
rep(i,1,q+1) qs[i].clear();
rep(i,1,n+1) 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])
tot[x]+=fenw.query(y);
}
rep(i,1,n+1) {
int md=(lo[i]+up[i])/2;
if (tot[i]>=p[i]) up[i]=md,ok[i]=1;
else lo[i]=md+1;
}
}
rep(i,1,n+1) {
if (!ok[i]) puts("NIE");
else printf("%d\n",up[i]);
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
met.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | rep(i,1,m+1) scanf("%d",o+i),qv[o[i]].pb(i);
| ~~~~~^~~~~~~~~~
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,n+1) scanf("%d",p+i);
| ~~~~~^~~~~~~~~~
met.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
met.cpp:48:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | rep(i,1,q+1) scanf("%d%d%d",l+i,r+i,a+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16844 KB |
Output is correct |
2 |
Correct |
15 ms |
16796 KB |
Output is correct |
3 |
Correct |
14 ms |
16844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
16892 KB |
Output is correct |
2 |
Correct |
13 ms |
16884 KB |
Output is correct |
3 |
Correct |
14 ms |
16844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
18336 KB |
Output is correct |
2 |
Correct |
194 ms |
20600 KB |
Output is correct |
3 |
Correct |
141 ms |
20124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
19500 KB |
Output is correct |
2 |
Correct |
159 ms |
19588 KB |
Output is correct |
3 |
Correct |
191 ms |
20804 KB |
Output is correct |
4 |
Correct |
52 ms |
19000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
168 ms |
18860 KB |
Output is correct |
2 |
Correct |
225 ms |
21240 KB |
Output is correct |
3 |
Correct |
153 ms |
17476 KB |
Output is correct |
4 |
Correct |
148 ms |
20584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
17944 KB |
Output is correct |
2 |
Correct |
169 ms |
19520 KB |
Output is correct |
3 |
Correct |
109 ms |
18272 KB |
Output is correct |
4 |
Correct |
213 ms |
21992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1205 ms |
36212 KB |
Output is correct |
2 |
Incorrect |
892 ms |
22840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1165 ms |
34672 KB |
Output is correct |
2 |
Incorrect |
911 ms |
22832 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |