//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lowbit(int x){return x&-x;}
int bit[500005];
void upd(int pl,int v){
while(pl){
bit[pl]+=v;
pl-=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl<=500000){
ret+=bit[pl];
pl+=lowbit(pl);
}
return ret;
}
int m;int n;
vector<int>own[500005];
int tgt[500005];
int lar[500005];
int rar[500005];
int opad[500005];
int Q;
int ans[500005];
void doop(int l,int r){
for(int i=l;i<=r;i++){
if(lar[i]<=rar[i]){
upd(rar[i],opad[i]);
upd(lar[i]-1,-opad[i]);
}else{
upd(rar[i],opad[i]);
upd(n,opad[i]);
upd(lar[i]-1,-opad[i]);
}
}
}
void undo(int l,int r){
for(int i=l;i<=r;i++){
if(lar[i]<=rar[i]){
upd(rar[i],-opad[i]);
upd(lar[i]-1,opad[i]);
}else{
upd(rar[i],-opad[i]);
upd(n,-opad[i]);
upd(lar[i]-1,opad[i]);
}
}
}
void solve(int l,int r,vector<int>qid){
if(l==r){
for(int i=0;i<qid.size();i++){
ans[qid[i]]=l;
}
return;
}
int mi=(l+r)/2;
doop(l,mi);
vector<int>qa;vector<int>qb;
for(int i=0;i<qid.size();i++){
int id=qid[i];
int cal=0;
for(int j=0;j<own[id].size();j++){
int pl=own[id][j];
cal+=qsum(pl);
}
if(cal>=tgt[id]){
qa.push_back(id);
}else{
qb.push_back(id);
}
}
//vector<int>().swap(qid);
solve(mi+1,r,qb);
undo(l,mi);
solve(l,mi,qa);
}
signed main(){
cin>>m>>n;
for(int i=1;i<=n;i++){
int v;
cin>>v;
own[v].push_back(i);
}
for(int i=1;i<=m;i++){
cin>>tgt[i];
}
cin>>Q;
for(int i=1;i<=Q;i++){
cin>>lar[i]>>rar[i]>>opad[i];
}
lar[Q+1]=1;
rar[Q+1]=1;
opad[Q+1]=0;
vector<int>vc;
for(int i=1;i<=m;i++){
vc.push_back(i);
}
solve(1,Q+1,vc);
for(int i=1;i<=m;i++){
if(ans[i]==Q+1){
cout<<"NIE\n";
}else{
cout<<ans[i]<<"\n";
}
}
}
Compilation message
met.cpp: In function 'void solve(long long int, long long int, std::vector<long long int>)':
met.cpp:59:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<qid.size();i++){
| ~^~~~~~~~~~~
met.cpp:68:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=0;i<qid.size();i++){
| ~^~~~~~~~~~~
met.cpp:71:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int j=0;j<own[id].size();j++){
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12116 KB |
Output is correct |
3 |
Correct |
7 ms |
12156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12212 KB |
Output is correct |
3 |
Correct |
6 ms |
12244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
15672 KB |
Output is correct |
2 |
Correct |
121 ms |
21224 KB |
Output is correct |
3 |
Correct |
99 ms |
15360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
14996 KB |
Output is correct |
2 |
Correct |
97 ms |
15044 KB |
Output is correct |
3 |
Correct |
118 ms |
19024 KB |
Output is correct |
4 |
Correct |
40 ms |
15568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
14884 KB |
Output is correct |
2 |
Correct |
83 ms |
19212 KB |
Output is correct |
3 |
Correct |
47 ms |
13316 KB |
Output is correct |
4 |
Correct |
100 ms |
15772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
14280 KB |
Output is correct |
2 |
Correct |
95 ms |
15084 KB |
Output is correct |
3 |
Correct |
85 ms |
14392 KB |
Output is correct |
4 |
Correct |
110 ms |
17352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1070 ms |
48584 KB |
Output is correct |
2 |
Incorrect |
518 ms |
23964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
941 ms |
42104 KB |
Output is correct |
2 |
Incorrect |
363 ms |
23956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |