답안 #120781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120781 2019-06-25T13:13:33 Z popovicirobert Meteors (POI11_met) C++14
100 / 100
5085 ms 40896 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

/*
const int MOD = ;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}


inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}
*/

using namespace std;

const ll INF = 1e9;
const int MAXN = (int) 3e5;

ll aint[4 * MAXN + 1];

void update(int nod, int left, int right, int l, int r, int val) {
    if(l <= left && right <= r) {
        aint[nod] += val;
    }
    else {
        int mid = (left + right) / 2;

        if(l <= mid) update(2 * nod, left, mid, l, r, val);
        if(mid < r) update(2 * nod + 1, mid + 1, right, l, r, val);
    }
}

ll query(int nod, int left, int right, int pos) {
    if(left == right) {
        return aint[nod];
    }
    else {
        int mid = (left + right) / 2;
        ll ans = aint[nod];

        if(pos <= mid) ans += query(2 * nod, left, mid, pos);
        else ans += query(2 * nod + 1, mid + 1, right, pos);

        return ans;
    }
}

vector <int> pos[MAXN + 1];
int q[MAXN + 1];
int l[MAXN + 1], r[MAXN + 1], a[MAXN + 1];
int n, m, k;

pair <int, int> res[MAXN + 1];

inline void check(int step) {
    for(int i = 1; i <= 4 * m; i++) {
        aint[i] = 0;
    }
    sort(res + 1, res + n + 1);

    int p = 1;
    for(int i = 1; i <= n; i++) {
        while(p <= res[i].first + step && p <= k) {
            if(l[p] <= r[p]) {
                update(1, 1, m, l[p], r[p], a[p]);
            }
            else {
                update(1, 1, m, 1, r[p], a[p]);
                update(1, 1, m, l[p], m, a[p]);
            }
            p++;
        }

        ll cur = 0;
        for(auto it : pos[res[i].second]) {
            cur += query(1, 1, m, it);
            cur = min(cur, INF);
        }
        if(cur < q[res[i].second]) {
            res[i].first += step;
        }
    }
}


int sol[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m;
    for(i = 1; i <= m; i++) {
        int o;
        cin >> o;
        pos[o].push_back(i);
    }
    for(i = 1; i <= n; i++) {
        cin >> q[i];
    }

    cin >> k;
    for(i = 1; i <= k; i++) {
        cin >> l[i] >> r[i] >> a[i];
    }

    for(i = 1; i <= n; i++) {
        res[i] = {-1, i};
    }
    for(int step = 1 << 18; step; step >>= 1) {
        check(step);
    }

    for(i = 1; i <= n; i++) {
        sol[res[i].second] = res[i].first + 1;
    }
    for(i = 1; i <= n; i++) {
        if(sol[i] == (1 << 19) - 1) {
            cout << "NIE\n";
        }
        else {
            cout << sol[i] << "\n";
        }
    }

    //cin.close();
    //cout.close();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7552 KB Output is correct
2 Correct 15 ms 7552 KB Output is correct
3 Correct 14 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7552 KB Output is correct
2 Correct 13 ms 7552 KB Output is correct
3 Correct 14 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 10876 KB Output is correct
2 Correct 419 ms 11880 KB Output is correct
3 Correct 396 ms 11528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 11256 KB Output is correct
2 Correct 392 ms 11384 KB Output is correct
3 Correct 438 ms 12024 KB Output is correct
4 Correct 102 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 10868 KB Output is correct
2 Correct 239 ms 12024 KB Output is correct
3 Correct 81 ms 8576 KB Output is correct
4 Correct 428 ms 11768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 10872 KB Output is correct
2 Correct 359 ms 11384 KB Output is correct
3 Correct 342 ms 11064 KB Output is correct
4 Correct 395 ms 12156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4101 ms 27864 KB Output is correct
2 Correct 552 ms 23104 KB Output is correct
3 Correct 446 ms 12920 KB Output is correct
4 Correct 5085 ms 39160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4346 ms 27232 KB Output is correct
2 Correct 923 ms 23272 KB Output is correct
3 Correct 125 ms 13176 KB Output is correct
4 Correct 4557 ms 40896 KB Output is correct