Submission #358621

# Submission time Handle Problem Language Result Execution time Memory
358621 2021-01-26T02:15:33 Z mjhmjh1104 Meteors (POI11_met) C++14
74 / 100
1222 ms 21712 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

long long tree[300006];

long long query(int x) {
    long long ret = 0;
    while (x > 0) {
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

void update_fenwick(int x, long long v) {
    while (x < 300006) {
        tree[x] += v;
        x += x & -x;
    }
}

void update(int l, int r, long long v) {
    update_fenwick(l, v);
    update_fenwick(r + 1, -v);
}

struct Query {
    int q;
    int l;
    int r;
    int m;
};

int n, m, p[300006], q;
vector<pair<pair<int, int>, int>> updates;
vector<Query> queries;
vector<int> o[300006];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        int t;
        scanf("%d", &t);
        o[t - 1].push_back(i);
    }
    for (int i = 0; i < n; i++) scanf("%d", p + i);
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int a, b, x;
        scanf("%d%d%d", &a, &b, &x);
        a--, b--;
        updates.push_back({ { a, b }, x });
    }
    for (int i = 0; i < n; i++) queries.push_back(Query{ i, 0, 300002, 150000 });
    for (int t = 0; t < 20; t++) {
        sort(queries.begin(), queries.end(), [](const Query &a, const Query &b) {
            return a.m < b.m;
        });
        fill(tree, tree + 300006, 0);
        int k = 0;
        for (int i = 0; i < q; i++) {
            while (k < n && i >= queries[k].m) {
                if (queries[k].l < queries[k].r) {
                    long long sum = 0;
                    for (auto &j: o[queries[k].q]) sum += query(j + 1);
                    if (sum >= p[queries[k].q]) queries[k].r = queries[k].m;
                    else queries[k].l = queries[k].m + 1;
                    queries[k].m = (queries[k].l + queries[k].r) / 2;
                }
                k++;
            }
            if (updates[i].first.first <= updates[i].first.second) update(updates[i].first.first + 1, updates[i].first.second + 1, updates[i].second);
            else update(updates[i].first.first + 1, m, updates[i].second), update(1, updates[i].first.second + 1, updates[i].second);
        }
        for (; k < n; k++) if (queries[k].l < queries[k].r) {
            long long sum = 0;
            for (auto &j: o[queries[k].q]) sum += query(j + 1);
            if (sum >= p[queries[k].q]) queries[k].r = queries[k].m;
            else queries[k].l = queries[k].m + 1;
            queries[k].m = (queries[k].l + queries[k].r) / 2;
        }
    }
    sort(queries.begin(), queries.end(), [](const Query &a, const Query &b) {
        return a.q < b.q;
    });
    for (auto &i: queries) {
        if (i.l >= 300002) puts("NIE");
        else printf("%d\n", i.l);
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
met.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~
met.cpp:48:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     for (int i = 0; i < n; i++) scanf("%d", p + i);
      |                                 ~~~~~^~~~~~~~~~~~~
met.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
met.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |         scanf("%d%d%d", &a, &b, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 9708 KB Output is correct
2 Correct 16 ms 9708 KB Output is correct
3 Correct 16 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9708 KB Output is correct
2 Correct 17 ms 9708 KB Output is correct
3 Correct 17 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10852 KB Output is correct
2 Correct 221 ms 11976 KB Output is correct
3 Correct 148 ms 11492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 11260 KB Output is correct
2 Correct 173 ms 11232 KB Output is correct
3 Correct 221 ms 12156 KB Output is correct
4 Correct 61 ms 10856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 10980 KB Output is correct
2 Correct 226 ms 12264 KB Output is correct
3 Correct 209 ms 10468 KB Output is correct
4 Correct 157 ms 11876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 10772 KB Output is correct
2 Correct 201 ms 11244 KB Output is correct
3 Correct 132 ms 10872 KB Output is correct
4 Correct 206 ms 12260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1222 ms 21712 KB Output is correct
2 Incorrect 740 ms 15224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1196 ms 21076 KB Output is correct
2 Incorrect 752 ms 15064 KB Output isn't correct
3 Halted 0 ms 0 KB -