Submission #1091112

# Submission time Handle Problem Language Result Execution time Memory
1091112 2024-09-19T20:45:27 Z ThylOne Meteors (POI11_met) C++14
74 / 100
972 ms 34184 KB
//####################
//Meteors
//####################
#include<bits/stdc++.h>

#define int long long 
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.begin(), x.end()


int nbState,nbPlanet;
const int maxiState = 300005;
ll attempt[maxiState];
vector<int> representant[maxiState];
int nbMeteor;
const int maxiMeteor = 300005;
struct meteor{
    int l,r;
    ll a;
};
meteor meteors[maxiMeteor];
#define LSONE(x) (x&(-x))
struct fenwick{
    vector<ll> val;
    fenwick(int n){
        val.resize(n+2);
        fill(all(val),0);
    }
    void update(int pos, ll v){
        while(pos<(int)val.size()){
            val[pos] += v;
            pos += LSONE(pos);
        }
    }
    ll rsq(int i){
        ll re = 0;
        while(i>0){
            re += val[i];
            i -= LSONE(i);
        }
        return re;
    }
    ll rsq(int i,int j){
        return rsq(j) - rsq(i - 1);
    }
    void ruq(int i,int j, ll a){
        update(i, a);
        update(j+1,-a);
    }
};
int mid(pair<int,int> a){
    return (a.first+a.second) >> 1;
}
void solve(){
    pair<int,int> ranges[nbState];
    fill(ranges,ranges+nbState,make_pair(1,nbMeteor+1));
    const int LOG = 23;
    bool change = true;
    for(int l = 0; change; l++){
        change = false;
        vector<int> req[nbMeteor+2];
        for(int i=0;i<nbState;i++){
            if(ranges[i].first!=ranges[i].second)
                req[mid(ranges[i])].pb(i);
        }
        fenwick ft(nbPlanet);
        for(int t = 1; t<= nbMeteor; t++){
            meteor &met = meteors[t - 1];
            //application de la météorite
            if(met.l<=met.r){
                ft.update(met.l,met.a), ft.update(met.r+1,-met.a);
            }else{
                ft.update(1,met.a);
                ft.update(met.r+1, -met.a);
                ft.update(met.l,met.a);
            }

            for(int r:req[t]){
                change=true;
                ll tot = 0;
                for(int repr:representant[r])tot+=ft.rsq(repr);
                if(tot>=attempt[r]){
                    ranges[r].second = t;
                }else{
                    ranges[r].first = t+1;
                }
            }
        }
    }
    for(int i = 0; i < nbState ; i++){
        if(ranges[i].first<=nbMeteor){
            cout<<ranges[i].first<<'\n';
        }else{
            cout<<"NIE\n";
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>nbState>>nbPlanet;
    for(int i = 0; i<nbPlanet;i++){
        int v;cin>>v;
        v--;
        representant[v].pb(i + 1);
    }
    for(int i= 0;i<nbState;i++)
        cin>>attempt[i];

    cin>>nbMeteor;
    for(int i = 0; i< nbMeteor ; i++){
        cin>>meteors[i].l>>meteors[i].r>>meteors[i].a;
    }
    solve();

    return 0;
};

Compilation message

met.cpp: In function 'void solve()':
met.cpp:60:15: warning: unused variable 'LOG' [-Wunused-variable]
   60 |     const int LOG = 23;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7516 KB Output is correct
2 Correct 4 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11732 KB Output is correct
2 Correct 96 ms 12868 KB Output is correct
3 Correct 74 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 11988 KB Output is correct
2 Correct 73 ms 13184 KB Output is correct
3 Correct 98 ms 14084 KB Output is correct
4 Correct 21 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11864 KB Output is correct
2 Correct 68 ms 13900 KB Output is correct
3 Correct 38 ms 11096 KB Output is correct
4 Correct 71 ms 13536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 11476 KB Output is correct
2 Correct 88 ms 11992 KB Output is correct
3 Correct 53 ms 11612 KB Output is correct
4 Correct 91 ms 14264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 927 ms 34176 KB Output is correct
2 Incorrect 656 ms 34184 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 972 ms 33604 KB Output is correct
2 Incorrect 653 ms 32732 KB Output isn't correct
3 Halted 0 ms 0 KB -