답안 #548558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548558 2022-04-13T19:46:55 Z 2fat2code Meteors (POI11_met) C++17
74 / 100
874 ms 36704 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int nmax = 300005;

int n, m, k, a[nmax], p[nmax], x[nmax], y[nmax], z[nmax], ans[nmax], curr, tree[nmax];

vector<int>members[nmax];

void add(int pos, int val){
    for(int i=pos;i<nmax;i+=(i&-i)){
        tree[i] += val;
    }
}

int query(int pos){
    if(!pos) return 0LL;
    int ans = 0;
    for(int i=pos;i>=1;i-=(i&-i)){
        ans += tree[i];
    }
    return ans;
}

void rec(int l, int r, vector<int>&pending){
    if(r < l) return;
    int mid = l + (r - l) / 2;
    while(curr < mid){
        curr++;
        if(x[curr] <= y[curr]){
            add(x[curr], z[curr]);
            add(y[curr]+1, (-1LL)*z[curr]);
        }
        else{
            add(x[curr], z[curr]);
            add(m+1, (-1LL)*z[curr]);
            add(1, z[curr]);
            add(y[curr]+1, (-1LL)*z[curr]);
        }
    }
    while(curr > mid){
        int fuck = z[curr] * (-1LL);
        if(x[curr] <= y[curr]){
            add(x[curr], fuck);
            add(y[curr]+1, (-1LL)*fuck);
        }
        else{
            add(x[curr], fuck);
            add(m+1, (-1LL)*fuck);
            add(1, fuck);
            add(y[curr]+1, (-1LL)*fuck);
        }
        --curr;
    }
    vector<int>good;
    vector<int>bad;
    for(auto it : pending){
        int curr = 0;
        for(auto it1 : members[it]){
            curr += (query(it1));
        }
        if(curr >= p[it]){
            good.push_back(it);
            ans[it] = mid;
        }
        else{
            bad.push_back(it);
        }
    }
    pending.clear();
    if(l != r){
        rec(l, mid - 1, good);
        rec(mid + 1, r, bad);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    //freopen("input.in", "r", stdin);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> a[i];
        members[a[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){ cin >> p[i];}
    cin >> k;
    for(int i=1;i<=k;i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    vector<int>tz;
    for(int i=1;i<=n;i++) tz.push_back(i);
    rec(1, k, tz);
    for(int i=1;i<=n;i++){
        if(!ans[i]){
            cout << "NIE" << '\n';
        }
        else{
            cout << ans[i] << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7508 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 7 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 6 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 10828 KB Output is correct
2 Correct 121 ms 14056 KB Output is correct
3 Correct 81 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 10696 KB Output is correct
2 Correct 90 ms 10536 KB Output is correct
3 Correct 127 ms 12700 KB Output is correct
4 Correct 30 ms 10448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 10460 KB Output is correct
2 Correct 121 ms 13008 KB Output is correct
3 Correct 71 ms 8668 KB Output is correct
4 Correct 73 ms 11020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 9932 KB Output is correct
2 Correct 122 ms 10548 KB Output is correct
3 Correct 70 ms 10056 KB Output is correct
4 Correct 112 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 874 ms 36704 KB Output is correct
2 Incorrect 525 ms 21564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 806 ms 33224 KB Output is correct
2 Incorrect 494 ms 21552 KB Output isn't correct
3 Halted 0 ms 0 KB -