Submission #548562

# Submission time Handle Problem Language Result Execution time Memory
548562 2022-04-13T19:55:09 Z 2fat2code Meteors (POI11_met) C++17
100 / 100
915 ms 39288 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int nmax = 300005;

int n, m, k, a[nmax], p[nmax], x[nmax], y[nmax], z[nmax], ans[nmax], curr, tree[nmax];

vector<int>members[nmax];

void add(int pos, int val){
    for(int i=pos;i<nmax;i+=(i&-i)){
        tree[i] += val;
    }
}

int query(int pos){
    int ans = 0;
    for(int i=pos;i>=1;i-=(i&-i)){
        ans += tree[i];
    }
    return ans;
}

void rec(int l, int r, vector<int>&pending){
    if(r < l) return;
    int mid = l + (r - l) / 2;
    while(curr < mid){
        curr++;
        if(x[curr] <= y[curr]){
            add(x[curr], z[curr]);
            add(y[curr]+1, (-1LL)*z[curr]);
        }
        else{
            add(x[curr], z[curr]);
            add(m+1, (-1LL)*z[curr]);
            add(1, z[curr]);
            add(y[curr]+1, (-1LL)*z[curr]);
        }
    }
    while(curr > mid){
        int fuck = z[curr] * (-1LL);
        if(x[curr] <= y[curr]){
            add(x[curr], fuck);
            add(y[curr]+1, (-1LL)*fuck);
        }
        else{
            add(x[curr], fuck);
            add(m+1, (-1LL)*fuck);
            add(1, fuck);
            add(y[curr]+1, (-1LL)*fuck);
        }
        --curr;
    }
    vector<int>good;
    vector<int>bad;
    for(auto it : pending){
        int curr = 0;
        for(auto it1 : members[it]){
            curr += (query(it1));
            if(curr >= p[it]) break;
        }
        if(curr >= p[it]){
            good.push_back(it);
            ans[it] = mid;
        }
        else{
            bad.push_back(it);
        }
    }
    pending.clear();
    if(l != r){
        rec(l, mid - 1, good);
        rec(mid + 1, r, bad);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    //freopen("input.in", "r", stdin);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> a[i];
        members[a[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){ cin >> p[i];}
    cin >> k;
    for(int i=1;i<=k;i++){
        cin >> x[i] >> y[i] >> z[i];
        assert(1 <= x[i] && x[i] <= m);
        assert(1 <= y[i] && y[i] <= m);
    }
    vector<int>tz;
    for(int i=1;i<=n;i++) tz.push_back(i);
    rec(1, k, tz);
    for(int i=1;i<=n;i++){
        if(!ans[i]){
            cout << "NIE" << '\n';
        }
        else{
            cout << ans[i] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 6 ms 7532 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 10744 KB Output is correct
2 Correct 119 ms 14076 KB Output is correct
3 Correct 74 ms 10948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10572 KB Output is correct
2 Correct 86 ms 10540 KB Output is correct
3 Correct 105 ms 12788 KB Output is correct
4 Correct 24 ms 10420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 10416 KB Output is correct
2 Correct 110 ms 12996 KB Output is correct
3 Correct 74 ms 8668 KB Output is correct
4 Correct 67 ms 11088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 9940 KB Output is correct
2 Correct 103 ms 10560 KB Output is correct
3 Correct 56 ms 10116 KB Output is correct
4 Correct 104 ms 12168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 709 ms 36608 KB Output is correct
2 Correct 382 ms 21612 KB Output is correct
3 Correct 406 ms 13340 KB Output is correct
4 Correct 786 ms 35728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 33152 KB Output is correct
2 Correct 450 ms 21604 KB Output is correct
3 Correct 319 ms 12244 KB Output is correct
4 Correct 915 ms 39288 KB Output is correct