Submission #1340463

#TimeUsernameProblemLanguageResultExecution timeMemory
1340463yusuf12360Meteors (POI11_met)C++20
74 / 100
593 ms22564 KiB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi> 
#define pb push_back
#define fi first
#define se second
#define TII tuple<int, int, int>
#define MT make_tuple
#define mp make_pair
#define ts to_string
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define MIN(x) *min_element(all(x))
#define MAX(x) *max_element(all(x))
#define lb lower_bound
#define ub upper_bound
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 5;
vi sec[N], stat[N];
int req[N], L[N], R[N], ans[N];
ll tr[N];
int l[N], r[N], v[N];
void upd(int i, int v) {
    for(; i < N; i += (-i & i)) tr[i] += v;
}
ll get(int i) {
    ll ret = 0;
    for(; i; i -= (-i & i)) ret += tr[i];
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m; cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int o; cin >> o;
        sec[o].pb(i);
    }
    for(int i = 1; i <= n; i++) cin >> req[i];

    int q; cin >> q;
    for(int i = 1; i <= q; i++) cin >> l[i] >> r[i] >> v[i];
    for(int i = 1; i <= n; i++) L[i] = 1, R[i] = q;

    while(1) {
        bool ex = 1;
        for(int i = 1; i <= n; i++) {
            if(L[i] > R[i]) continue;
            if(L[i] < R[i]) ex = 0;
            int mid = L[i] + R[i] >> 1;
            stat[mid].pb(i);
        }

        for(int i = 1; i < N; i++) tr[i] = 0;

        // cerr << "___________" << z << endl;
        for(int i = 1; i <= q; i++) {
            if(l[i] <= r[i]) upd(l[i], v[i]), upd(r[i] + 1, -v[i]);
            else upd(l[i], v[i]), upd(m + 1, -v[i]), upd(1, v[i]), upd(r[i] + 1, -v[i]);

            // cerr << "seq : " << flush;
            // for(int j = 1; j <= m; j++) cerr << get(j) << ' '; cerr << endl; 

            for(int st : stat[i]) {
                ll cnt = 0;
                for(int j : sec[st]) cnt += get(j);
                
                // cerr << i << ' ' << st << " : " << cnt << endl;
                if(cnt >= req[st]) ans[st] = i, R[st] = i - 1;
                else L[st] = i + 1;
            }
            stat[i].clear();
        }

        if(ex) break;
    }

    for(int i = 1; i <= n; i++) {
        if(ans[i]) cout << ans[i] << '\n';
        else cout << "NIE" << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...