답안 #818109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818109 2023-08-10T02:21:03 Z 1075508020060209tc Meteors (POI11_met) C++14
74 / 100
1037 ms 56488 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]){
        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++){
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 8 ms 12232 KB Output is correct
3 Correct 8 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12200 KB Output is correct
2 Correct 9 ms 12168 KB Output is correct
3 Correct 8 ms 12204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 16452 KB Output is correct
2 Correct 111 ms 22396 KB Output is correct
3 Correct 98 ms 16400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 16060 KB Output is correct
2 Correct 97 ms 16048 KB Output is correct
3 Correct 131 ms 20088 KB Output is correct
4 Correct 41 ms 16024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 15616 KB Output is correct
2 Correct 82 ms 20460 KB Output is correct
3 Correct 47 ms 13856 KB Output is correct
4 Correct 101 ms 16856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 15172 KB Output is correct
2 Correct 98 ms 16252 KB Output is correct
3 Correct 97 ms 15440 KB Output is correct
4 Correct 111 ms 18516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1037 ms 56488 KB Output is correct
2 Incorrect 513 ms 31784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1024 ms 49712 KB Output is correct
2 Incorrect 404 ms 30336 KB Output isn't correct
3 Halted 0 ms 0 KB -