답안 #762613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762613 2023-06-21T14:45:54 Z vjudge1 Meteors (POI11_met) C++17
100 / 100
1073 ms 56052 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];
ll 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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7520 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7520 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 10856 KB Output is correct
2 Correct 95 ms 13924 KB Output is correct
3 Correct 76 ms 11240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 13096 KB Output is correct
2 Correct 83 ms 13124 KB Output is correct
3 Correct 94 ms 13584 KB Output is correct
4 Correct 23 ms 9296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 12800 KB Output is correct
2 Correct 71 ms 13452 KB Output is correct
3 Correct 36 ms 10136 KB Output is correct
4 Correct 74 ms 11364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12868 KB Output is correct
2 Correct 88 ms 13124 KB Output is correct
3 Correct 59 ms 10868 KB Output is correct
4 Correct 91 ms 13676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 773 ms 50964 KB Output is correct
2 Correct 479 ms 46180 KB Output is correct
3 Correct 174 ms 18644 KB Output is correct
4 Correct 968 ms 54848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 50688 KB Output is correct
2 Correct 494 ms 46240 KB Output is correct
3 Correct 155 ms 18056 KB Output is correct
4 Correct 1073 ms 56052 KB Output is correct