Submission #496998

# Submission time Handle Problem Language Result Execution time Memory
496998 2021-12-22T08:11:43 Z Nalrimet Meteors (POI11_met) C++17
100 / 100
4190 ms 65536 KB
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1

using namespace std;

typedef long long ll;

const ll N = (ll) 3e5 + 17;
const ll M = (ll) 5e3 + 69;

int n, m, q, a[N];
ll upd[N * 4];
int  x[N], l[N], r[N];
int ql[N], qr[N];

vector<int> v[N], vq[N];

ll get(int v, int tl, int tr, int pos) {
    if(tl == tr) return upd[v];
    int tm = (tl + tr) / 2;
    if(pos <= tm) return get(left(v), tl, tm, pos) + upd[v];
    else return get(right(v), tm + 1, tr, pos) + upd[v];
}

void update(int v, int tl, int tr, int ql, int qr, ll val) {
    if(tr < ql || qr < tl) return;
    if(ql <= tl && tr <= qr){
		upd[v] += val;
        return;
    }
    int mid = (tl + tr) / 2;
    update(left(v), tl, mid, ql, qr, val);
    update(right(v), mid + 1, tr, ql, qr, val);
}

 main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for(int i = 1, p; i <= m; i++) {
        cin >> p;
        v[p].pb(i);
    }

    for(int i = 1; i <= n; i++)
        cin >> a[i];

    cin >> q;

    for(int i = 1; i <= n; i++)
        ql[i] = 1, qr[i] = q + 1;

    for(int i = 1; i <= q; i++)
        cin >> l[i] >> r[i] >> x[i];

    int ok = 1;
    while(ok){
        ok = 0;
        memset(upd, 0, sizeof(upd));
        for(int i = 1; i <= n; i++)
            if(ql[i] != qr[i])
                vq[(ql[i] + qr[i]) / 2].pb(i);

        for(int i = 1; i <= q; i++){
            if(l[i] <= r[i])
                update(1, 1, m, l[i], r[i], x[i]);
            else update(1, 1, m, l[i], m, x[i]), update(1, 1, m, 1, r[i], x[i]);
            for(int id : vq[i]){
                ok = 1;
                ll sum = 0;
                for(int x : v[id]) {
                    sum += get(1, 1, m, x);
                    if(sum >= a[id]) break;
                }
                if(sum >= a[id]) qr[id] = i;
                else ql[id] = i + 1;
            }
          	vq[i].clear();
        }
    }

    for(int i = 1; i <= n; i++) {
        if(ql[i] == q + 1) cout << "NIE\n";
        else cout << ql[i] << '\n';
    }
}

Compilation message

met.cpp:43:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 |  main() {
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23864 KB Output is correct
2 Correct 22 ms 23872 KB Output is correct
3 Correct 22 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23864 KB Output is correct
2 Correct 22 ms 23824 KB Output is correct
3 Correct 26 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 25172 KB Output is correct
2 Correct 404 ms 27052 KB Output is correct
3 Correct 406 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 26252 KB Output is correct
2 Correct 377 ms 26172 KB Output is correct
3 Correct 374 ms 27244 KB Output is correct
4 Correct 94 ms 25604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 25604 KB Output is correct
2 Correct 279 ms 27660 KB Output is correct
3 Correct 172 ms 24596 KB Output is correct
4 Correct 364 ms 27192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 24668 KB Output is correct
2 Correct 308 ms 26128 KB Output is correct
3 Correct 329 ms 25008 KB Output is correct
4 Correct 386 ms 28360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3364 ms 40960 KB Output is correct
2 Correct 1291 ms 28752 KB Output is correct
3 Correct 798 ms 26976 KB Output is correct
4 Correct 4190 ms 62220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3282 ms 39504 KB Output is correct
2 Correct 862 ms 28812 KB Output is correct
3 Correct 669 ms 26208 KB Output is correct
4 Correct 3896 ms 65536 KB Output is correct