답안 #818140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818140 2023-08-10T02:45:52 Z 1075508020060209tc Meteors (POI11_met) C++14
74 / 100
1091 ms 31008 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);
    }
}
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 9 ms 12116 KB Output is correct
2 Correct 8 ms 12176 KB Output is correct
3 Correct 9 ms 12064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 9 ms 12116 KB Output is correct
3 Correct 8 ms 12184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 14540 KB Output is correct
2 Correct 110 ms 15684 KB Output is correct
3 Correct 103 ms 15024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 14744 KB Output is correct
2 Correct 105 ms 14900 KB Output is correct
3 Correct 126 ms 15648 KB Output is correct
4 Correct 37 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 14664 KB Output is correct
2 Correct 79 ms 15536 KB Output is correct
3 Correct 52 ms 13388 KB Output is correct
4 Correct 97 ms 15116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 14256 KB Output is correct
2 Correct 95 ms 14792 KB Output is correct
3 Correct 81 ms 14412 KB Output is correct
4 Correct 111 ms 15856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1091 ms 31008 KB Output is correct
2 Incorrect 491 ms 24084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 988 ms 30360 KB Output is correct
2 Incorrect 321 ms 24188 KB Output isn't correct
3 Halted 0 ms 0 KB -