Submission #498761

# Submission time Handle Problem Language Result Execution time Memory
498761 2021-12-26T10:07:52 Z tht2005 Meteors (POI11_met) C++17
74 / 100
468 ms 23372 KB
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

void io(string in = "", string out = "", string err = "") {
if(fopen(in.c_str(), "r")) {
    freopen(in.c_str(), "r", stdin);
    freopen(out.c_str(), "w", stdout);
#ifdef conv_local
    freopen(err.c_str(), "w", stderr);
#endif
}
}
void conv();

int main() {
#ifdef conv_local
    //io("in.txt", "out.txt", "err.txt");
    auto st = chrono::steady_clock::now();
#else
#define TASKNAME ""
    io(TASKNAME".inp", TASKNAME".out");
#endif
    ios::sync_with_stdio(false); cin.tie(NULL);
    int Q = 1;
    //cin >> Q;
    while(Q--) {
        conv();
    }
#ifdef conv_local
    auto ed = chrono::steady_clock::now();
    cout << "\nExcution Time: " << chrono::duration_cast<chrono::milliseconds> (ed - st).count() << "[ms]" << endl;
#endif
    return 0;
}

typedef long long LL;

const int N = 300003;
int n, m, q, l[N], r[N], a[N], res[N];
LL f[N], p[N];
vector<int> o[N];

void add(int x, LL d) {
    for(; x <= m; x += x&-x) f[x] += d;
}
LL query(int x) {
    LL ret = 0;
    for(; x > 0; x &= x - 1) ret += f[x];
    return ret;
}
void add_range(int ql, int qr, LL d) {
    add(ql, d);
    add(qr + 1, -d);
    if(ql > qr) add(1, d);
}
void solve(int ql, int qr, const vector<int>& v) {
    if(ql == qr || v.empty()) {
        for(int i : v) res[i] = ql;
    }
    else {
        int qm = (ql + qr) >> 1;
        for(int i = ql; i <= qm; ++i) add_range(l[i], r[i], a[i]);
        vector<int> ok, n_ok;
        for(int i : v) {
            LL tot = 0;
            for(int j : o[i]) tot += query(j);
            if(tot >= p[i]) ok.push_back(i);
            else p[i] -= tot, n_ok.push_back(i);
        }
        for(int i = ql; i <= qm; ++i) add_range(l[i], r[i], -a[i]);
        solve(ql, qm, ok);
        solve(qm + 1, qr, n_ok);
    }
}
void conv() {
    cin >> n >> m;
    for(int i = 1; i <= m; ++i) {
        int j;
        cin >> j;
        o[j].push_back(i);
    }
    for(int i = 1; i <= n; ++i) cin >> p[i];
    cin >> q;
    for(int i = 1; i <= q; ++i) cin >> l[i] >> r[i] >> a[i];
    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    solve(1, q + 1, v);
    for(int i = 1; i <= n; ++i) {
        if(res[i] > q) cout << "NIE" << '\n';
        else cout << res[i] << '\n';
    }
}

Compilation message

met.cpp: In function 'void io(std::string, std::string, std::string)':
met.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen(in.c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen(out.c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 5 ms 7500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 9028 KB Output is correct
2 Correct 64 ms 12228 KB Output is correct
3 Correct 74 ms 10276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 9024 KB Output is correct
2 Correct 72 ms 10148 KB Output is correct
3 Correct 58 ms 11600 KB Output is correct
4 Correct 26 ms 9500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8932 KB Output is correct
2 Correct 69 ms 11768 KB Output is correct
3 Correct 21 ms 8496 KB Output is correct
4 Correct 75 ms 10696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 8652 KB Output is correct
2 Correct 82 ms 10236 KB Output is correct
3 Correct 49 ms 9684 KB Output is correct
4 Correct 84 ms 11324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 468 ms 23372 KB Output is correct
2 Incorrect 262 ms 22304 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 387 ms 21596 KB Output is correct
2 Incorrect 258 ms 20644 KB Output isn't correct
3 Halted 0 ms 0 KB -