답안 #1011902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011902 2024-07-01T10:51:04 Z atom Meteors (POI11_met) C++17
74 / 100
755 ms 43796 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
 
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif


#define int long long
const int N = 3e5 + 5;
 
struct FenwickTree {
    int n;
    vector <ll> f;
    void init(int _n) {
        n = _n;
        f.resize(n + 5, 0);  
    } 
 
    void modify(int x, int val) {
        for (; x <= n; x += x & -x) 
            f[x] += val;
    }
    void upd(int l, int r, int val) {
        if (l <= r) {
            modify(l, val);
            modify(r + 1, -val); 
        }
        else {
            modify(1, val);
            modify(r + 1, -val); 
            modify(l, val);
            modify(n + 1, -val); 
        }
 
    }
    ll qry(int x) {
        ll sum = 0;
        for (; x; x -= x & -x)
            sum += f[x];
        return sum;
    }
} bit;
 
vector <int> adj[N];
vector <int> qs[N];
int ans[N];
ll tar[N];
 
 
void dnc(int l, int r, vector <int>& cand) {
    if (l + 1 == r) {
        debug(l, r, cand);
        for (int x : cand) ans[x] = l;
        return;
    }
 
    int m = (l + r) / 2;
 
    vector <int> L, R;
    for (int i = l; i < m; ++i) {
        auto x = qs[i];
        bit.upd(x[0], x[1], x[2]);
    }
 
    vector <int> done, undone;
    for (auto x : cand) {
        ll sum = 0;
        for (int y : adj[x]) sum += bit.qry(y);
        if (sum >= tar[x]) {
            done.push_back(x);
        }
        else {
            tar[x] -= sum;
            undone.push_back(x);
        }
    }
 
    // reroll change as we no longer able to process
    for (int i = l; i < m; ++i) {
        auto x = qs[i];
        bit.upd(x[0], x[1], -x[2]);
    }
 
    dnc(l, m, done);
    dnc(m, r, undone);
}
 
int n, m;
int q;
 
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in1", "r", stdin);
    #endif
 
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int x; cin >> x;
        adj[x].push_back(i);
    }
    for (int i = 1; i <= n; ++i) 
        cin >> tar[i];
    
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        qs[i] = {l, r, c};
    }
    qs[q + 1] = {0, 0, 0};
 
    vector <int> cand(n);
    iota(cand.begin(), cand.end(), 1);
 
    bit.init(m);
    
    dnc(1, q + 2, cand);
    for (int i = 1; i <= n; ++i) {
        if (ans[i] == q + 1) cout << "NIE\n";
        else cout << ans[i] << "\n";
    }
    
    return 0;
}

Compilation message

met.cpp: In function 'void dnc(long long int, long long int, std::vector<long long int>&)':
met.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 166
      |                    ^~~
met.cpp:57:9: note: in expansion of macro 'debug'
   57 |         debug(l, r, cand);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 18280 KB Output is correct
2 Correct 88 ms 21456 KB Output is correct
3 Correct 68 ms 18192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 18008 KB Output is correct
2 Correct 71 ms 18040 KB Output is correct
3 Correct 76 ms 20064 KB Output is correct
4 Correct 17 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 18000 KB Output is correct
2 Correct 63 ms 20432 KB Output is correct
3 Correct 40 ms 16472 KB Output is correct
4 Correct 69 ms 18516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 17364 KB Output is correct
2 Correct 79 ms 18128 KB Output is correct
3 Correct 54 ms 17500 KB Output is correct
4 Correct 78 ms 19540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 43796 KB Output is correct
2 Incorrect 552 ms 29272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 636 ms 40172 KB Output is correct
2 Incorrect 524 ms 28884 KB Output isn't correct
3 Halted 0 ms 0 KB -