답안 #1089264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089264 2024-09-16T08:40:55 Z TrinhKhanhDung Meteors (POI11_met) C++14
74 / 100
1065 ms 29856 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

struct fen{
    vector<ll> tree;
    int n;

    fen(int _n = 0){
        n = _n;
        tree.resize(n + 3, 0);
    }

    void upd(int p, ll c){
        while(p <= n){
            tree[p] += c;
            p += p & -p;
        }
    }

    ll get(int p){
        ll ans = 0;
        while(p){
            ans += tree[p];
            p -= p & -p;
        }
        return ans;
    }
};

const int MAX = 3e5 + 10;

int N, M, Q;
int a[MAX], L[MAX], R[MAX], ans[MAX];
vector<int> pos[MAX];
vector<array<int, 3>> upds;

int cnp(){
    int cnt = 0;
    vector<pair<int, int>> ord;
    for(int i = 1; i <= N; i++) if(L[i] <= R[i]){
        cnt++;
        int m = (L[i] + R[i]) >> 1;
        ord.push_back(make_pair(m, i));
    }

    sort(ALL(ord));

    int j = 0;
    fen bit(M);
    for(int i = 0; i < Q; i++){
        int l = upds[i][0], r = upds[i][1], c = upds[i][2];
        bit.upd(l, c); bit.upd(r + 1, -c);
        if(l > r){
            bit.upd(1, c);
        }
        while(j < sz(ord) && ord[j].fi == i){
            int id = ord[j].se, m = ord[j].fi;
            j++;
            ll sum = 0;
            for(int x: pos[id]) sum += bit.get(x);
            if(sum >= a[id]){
                R[id] = m - 1;
                ans[id] = m;
            }
            else L[id] = m + 1;
        }
    }

    return cnt;
}

void solve(){
    cin >> N >> M;
    for(int i = 1; i <= M; i++){
        int x; cin >> x;
        pos[x].push_back(i);
    }
    for(int i = 1; i <= N; i++) cin >> a[i];
    cin >> Q;
    for(int i = 1; i <= Q; i++){
        int x, y, z; cin >> x >> y >> z;
        upds.push_back({x, y, z});
    }

    for(int i = 1; i <= N; i++){
        L[i] = 0; R[i] = Q - 1;
    }

    memset(ans, -1, sizeof ans);
//    cnp();
    while(cnp());
    for(int i = 1; i <= N; i++){
        if(ans[i] == -1) cout << "NIE\n";
        else cout << ans[i] + 1 << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("order.inp","r",stdin);
    // freopen("order.out","w",stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8540 KB Output is correct
2 Correct 7 ms 8540 KB Output is correct
3 Correct 5 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8540 KB Output is correct
2 Correct 4 ms 8760 KB Output is correct
3 Correct 5 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 11040 KB Output is correct
2 Correct 112 ms 12248 KB Output is correct
3 Correct 82 ms 11648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 11592 KB Output is correct
2 Correct 84 ms 11588 KB Output is correct
3 Correct 133 ms 12316 KB Output is correct
4 Correct 31 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 10980 KB Output is correct
2 Correct 96 ms 12360 KB Output is correct
3 Correct 37 ms 9936 KB Output is correct
4 Correct 89 ms 12004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 11012 KB Output is correct
2 Correct 102 ms 11504 KB Output is correct
3 Correct 52 ms 11080 KB Output is correct
4 Correct 119 ms 12404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1065 ms 29856 KB Output is correct
2 Incorrect 665 ms 23560 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1004 ms 29364 KB Output is correct
2 Incorrect 670 ms 22096 KB Output isn't correct
3 Halted 0 ms 0 KB -