제출 #1340449

#제출 시각아이디문제언어결과실행 시간메모리
1340449yusuf12360새로운 문제 (POI11_met)C++20
74 / 100
585 ms36892 KiB
#include<bits/stdc++.h>
#define int 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], tr[N];
TII qu[N];
void upd(int i, int v) {
    for(; i < N; i += (-i & i)) tr[i] += v;
}
int get(int i) {
    int ret = 0;
    for(; i; i -= (-i & i)) ret += tr[i];
    return ret;
}
int32_t 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++) {
        auto &[l, r, v] = qu[i];
        cin >> l >> r >> v;
    }
    for(int i = 1; i <= n; i++) L[i] = 1, R[i] = q;

    while(1) {
        for(int i = 1; i <= q; i++) stat[i].clear();
        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++) {
            auto [l, r, v] = qu[i];
            if(l <= r) upd(l, v), upd(r + 1, -v);
            else upd(l, v), upd(m + 1, -v), upd(1, v), upd(r + 1, -v);

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

            for(int st : stat[i]) {
                int 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;
            }
        }

        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...