Submission #762607

# Submission time Handle Problem Language Result Execution time Memory
762607 2023-06-21T14:39:37 Z Issa Meteors (POI11_met) C++17
74 / 100
726 ms 50176 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 3e5 + 100;
const ll INF = (ll)2e18;
const int inf = (ll)2e9;
const int maxl = 26;
const int MOD = 1e9 + 7;

int n, m, q;
vector<int> g[maxn];
int a[maxn];
int ans[maxn];
int t[maxn];
int l[maxn];
int r[maxn];
int x[maxn];
vector<int> cl;

void upd(int i, int x){
    for(; i <= m; i |= (i + 1)) t[i] += x, cl.push_back(i);
}

void upd(int l, int r, int x){
    if(l <= r){
        upd(l, x); upd(r + 1, -x);
    } else{
        upd(1, x);
        upd(r + 1, -x);
        upd(l, x);
    }
}

ll get(int i){
    ll res = 0;
    for(; i > 0; i = (i & (i + 1)) - 1) res += t[i];
    return res;
}

void f(int tl, int tr, vector<int> &v){
    if(tl > tr) return;
    int mid = (tl + tr) >> 1;
    vector<int> L, R;
    for(int i = tl; i <= mid; i++){
        upd(l[i], r[i], x[i]);
    }
    for(int x: v){
        ll sum = 0;
        for(int i: g[x]){
            sum = min((ll)1e18, 1ll * get(i) + sum);
        }
        if(a[x] > sum) a[x] -= sum, R.push_back(x);
        else ans[x] = mid, L.push_back(x);
    }
    for(int x: cl) t[x] = 0;
    cl.clear();
    f(tl, mid - 1, L);
    f(mid + 1, tr, R);
}

void test(){    
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x; cin >> x;
        g[x].push_back(i);
    }
    vector<int> v;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; v.push_back(i);
        ans[i] = -1;
    } 
    cin >> q;
    for(int i = 1; i <= q; i++){
        cin >> l[i] >> r[i] >> x[i];
    }
    f(1, q, v);
    for(int i = 1; i <= n; i++){
        if(ans[i] == -1) cout << "NIE\n";
        else cout << ans[i] << ent;
    }
}

int main(){
    // freopen("cows.in", "r", stdin);
    // freopen("cows.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t; t = 1;
    while(t--) test();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7512 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7448 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 10956 KB Output is correct
2 Correct 90 ms 13944 KB Output is correct
3 Correct 72 ms 11200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 13212 KB Output is correct
2 Correct 76 ms 13192 KB Output is correct
3 Correct 91 ms 13620 KB Output is correct
4 Correct 23 ms 9268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 13032 KB Output is correct
2 Correct 70 ms 13624 KB Output is correct
3 Correct 35 ms 10368 KB Output is correct
4 Correct 72 ms 11396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 12996 KB Output is correct
2 Correct 83 ms 13116 KB Output is correct
3 Correct 60 ms 10856 KB Output is correct
4 Correct 92 ms 13748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 726 ms 50176 KB Output is correct
2 Incorrect 465 ms 45864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 705 ms 49708 KB Output is correct
2 Incorrect 452 ms 46056 KB Output isn't correct
3 Halted 0 ms 0 KB -