답안 #644644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644644 2022-09-25T05:13:49 Z JJAnawat Meteors (POI11_met) C++14
74 / 100
872 ms 38900 KB
#include<bits/stdc++.h>

using namespace std;

const int MXN=300005;
int n,m,k;
int target[MXN],L[MXN],R[MXN];
vector<int> child[MXN];
vector<tuple<int,int,int>> shower;
long long fw[MXN];
vector<int> ask[MXN];

void upd(int x,int val){
    for(int i=x;i<=300000;i+=i&-i)
        fw[i]+=val;
}

long long qr(int x){
    long long sum=0;
    for(int i=x;i>=1;i-=i&-i)
        sum+=fw[i];
    return sum;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i=1,x;i<=m;i++){
        cin >> x;
        child[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
        cin >> target[i];
    cin >> k;
    for(int i=1,x,y,z;i<=k;i++){
        cin >> x >> y >> z;
        shower.push_back({x,y,z});
    }
    for(int i=1;i<=n;i++){
        L[i]=1;
        R[i]=k+1;
    }
    while(1){
        bool done=1;
        for(int i=1;i<=n;i++){
            if(L[i]<R[i]){
                done=0;
                ask[(L[i]+R[i])/2].push_back(i);
            }
        }
        if(done)
            break;
        memset(fw,0,sizeof(fw));
        for(int i=1;i<=k;i++){
            auto [l,r,a]=shower[i-1];
            if(l<=r){
                upd(l,a);
                upd(r+1,-a);
            }
            else{
                upd(l,a);
                upd(1,a);
                upd(r+1,-a);
            }

            for(auto it:ask[i]){
                long long sum=0;
                for(auto iit:child[it]){
                    sum+=qr(iit);
                }
                if(sum>=target[it])
                    R[it]=i;
                else
                    L[it]=i+1;
            }
            ask[i].clear();
        }
    }
    for(int i=1;i<=n;i++){
        if(L[i]<=k)
            cout << L[i] << "\n";
        else
            cout << "NIE\n";
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:57:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   57 |             auto [l,r,a]=shower[i-1];
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16724 KB Output is correct
2 Correct 11 ms 16784 KB Output is correct
3 Correct 11 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 11 ms 16780 KB Output is correct
3 Correct 11 ms 16872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 18968 KB Output is correct
2 Correct 122 ms 21320 KB Output is correct
3 Correct 102 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 20272 KB Output is correct
2 Correct 108 ms 20372 KB Output is correct
3 Correct 143 ms 21440 KB Output is correct
4 Correct 37 ms 19008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 19368 KB Output is correct
2 Correct 146 ms 21808 KB Output is correct
3 Correct 106 ms 18084 KB Output is correct
4 Correct 101 ms 21308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 18828 KB Output is correct
2 Correct 124 ms 20400 KB Output is correct
3 Correct 80 ms 19012 KB Output is correct
4 Correct 124 ms 22660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 851 ms 38900 KB Output is correct
2 Incorrect 626 ms 26612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 872 ms 37684 KB Output is correct
2 Incorrect 643 ms 26560 KB Output isn't correct
3 Halted 0 ms 0 KB -