Submission #819003

# Submission time Handle Problem Language Result Execution time Memory
819003 2023-08-10T07:36:35 Z 1075508020060209tc Meteors (POI11_met) C++14
100 / 100
1185 ms 56456 KB
#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]){break;}
    }
    if(cal>=tgt[id]){
        qa.push_back(id);
    }else{
        qb.push_back(id);
    }
}
qid.clear();
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:58:23: 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]
   58 | if(l==r){for(int i=0;i<qid.size();i++){ans[qid[i]]=l;}return; }
      |                      ~^~~~~~~~~~~
met.cpp:62: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]
   62 | for(int i=0;i<qid.size();i++){
      |             ~^~~~~~~~~~~
met.cpp:65: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]
   65 |     for(int j=0;j<own[id].size();j++){
      |                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 8 ms 12200 KB Output is correct
3 Correct 8 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12196 KB Output is correct
3 Correct 8 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16620 KB Output is correct
2 Correct 116 ms 22396 KB Output is correct
3 Correct 99 ms 16440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 16172 KB Output is correct
2 Correct 98 ms 16092 KB Output is correct
3 Correct 110 ms 19984 KB Output is correct
4 Correct 39 ms 15996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15608 KB Output is correct
2 Correct 84 ms 20420 KB Output is correct
3 Correct 53 ms 13912 KB Output is correct
4 Correct 100 ms 16788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15104 KB Output is correct
2 Correct 93 ms 16232 KB Output is correct
3 Correct 83 ms 15484 KB Output is correct
4 Correct 113 ms 18708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 974 ms 56456 KB Output is correct
2 Correct 435 ms 31764 KB Output is correct
3 Correct 221 ms 20356 KB Output is correct
4 Correct 1185 ms 48244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1059 ms 49764 KB Output is correct
2 Correct 290 ms 30228 KB Output is correct
3 Correct 207 ms 20308 KB Output is correct
4 Correct 1164 ms 55920 KB Output is correct