Submission #1015733

# Submission time Handle Problem Language Result Execution time Memory
1015733 2024-07-06T17:30:03 Z vjudge1 Meteors (POI11_met) C++17
74 / 100
573 ms 65536 KB
//
//  main1.cpp
//  problem1
//
//  Created by Essa Almousa on 2030 / 01/ 01 AD.
//

#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
using ll = __int128;
using ll1 = long long;
#define pb push_back
#define pF first
#define pS second
#define SP <<" "<<
const ll N = 3e5+10;

struct segment {
    vector<ll> tree;
    ll offset = 1;
    void it(ll n) {
        while (offset < n) offset *= 2;
        tree.resize(offset*2, 0);
    }
    void upd(ll v, ll l, ll r, ll ql, ll qr, ll x) {
        if (l >= qr || r <= ql) return;
        if (l >= ql && r <= qr) {tree[v] += x; return;}
        ll mi = (l+r)/2;
        upd(v*2, l, mi, ql, qr, x);
        upd(v*2+1, mi, r, ql, qr, x);
    }
    ll query(ll i) {
        i--;
        i += offset;
        ll ans = 0;
        while (i >= 1) {
            ans += tree[i];
            i /= 2;
        }
        return ans;
    }
    void upd(ll l, ll r, ll val) {return upd(1, 0, offset, l-1, r, val);}
};

struct query_ {
    ll l, r, x;
};
ll a[N], b[N];
ll1 sol[N];
vector<ll> frq[N];
query_ q[N];

int main() {
    //ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    ll1 n, m;
    cin>>n>>m;
    for (ll i=1; i<=m; i++) {
        int temp; cin >> temp;
        a[i] = temp;
        //cin>>a[i];
        frq[a[i]].pb(i);
    }
    
    for (ll i=1; i<=n; i++) {
        int temp; cin >> temp;
        b[i] = temp;
        //cin>>b[i];
    }
    
    ll1 q1;
    cin>>q1;
    
    struct binnode { ll i, m, l, r; };
    
    vector<binnode> bin[N];
    for (ll i=1; i<=n; i++) {
        ll mi = q1+1/2;
        bin[mi].pb({i, mi, 1, q1});
        sol[i] = -1;
    }

    for (ll i=1; i<=q1; i++) {
        ll1 l, r, x;
        cin>>l>>r>>x;
        q[i] = {l, r, x};
    }
    ll1 cnt = n;
    while (cnt > 0) {
        segment tree;
        tree.it(m);
        for (ll i=1; i<=q1; i++) {
            if (q[i].l > q[i].r) {
                tree.upd(q[i].l, m, q[i].x);
                tree.upd(1, q[i].r, q[i].x);
            }
            else tree.upd(q[i].l, q[i].r, q[i].x);
            
            for (ll1 j = bin[i].size()-1; j >= 0; j = bin[i].size()-1) {
                binnode& x = bin[i][j];
                ll ans = 0; // the num
                for (ll k=0; k < frq[x.i].size(); k++) ans += tree.query(frq[x.i][k]);
                if (ans >= b[x.i]) x.r = x.m;
                else {
                    if (x.l >= q1) {cnt--;bin[i].pop_back(); continue;};
                    x.l = x.m+1;
                }
                ll mid = (x.l+x.r)/2;
                if (x.l != x.r) {bin[mid].pb({x.i, mid, x.l, x.r}); cnt++;}
                else sol[x.i] = x.l;
                bin[i].pop_back();
                cnt--;
                j = bin[i].size() - 1;
            }
        }
    }
    for (ll i=1; i<=n; i++) {
        if (sol[i] == -1) cout << "NIE" << endl;
        else cout << sol[i] << endl;
    }
}

# Verdict Execution time Memory Grader output
1 Correct 9 ms 22052 KB Output is correct
2 Correct 9 ms 21848 KB Output is correct
3 Correct 9 ms 22108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22108 KB Output is correct
2 Correct 10 ms 22204 KB Output is correct
3 Correct 10 ms 22396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 32468 KB Output is correct
2 Correct 520 ms 34252 KB Output is correct
3 Correct 494 ms 48448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 498 ms 44092 KB Output is correct
2 Correct 531 ms 44360 KB Output is correct
3 Correct 573 ms 63300 KB Output is correct
4 Correct 65 ms 37956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 37656 KB Output is correct
2 Correct 399 ms 44984 KB Output is correct
3 Correct 223 ms 27356 KB Output is correct
4 Correct 488 ms 51636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 32772 KB Output is correct
2 Correct 544 ms 43716 KB Output is correct
3 Correct 430 ms 34972 KB Output is correct
4 Correct 535 ms 59448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 258 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 259 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -