Submission #359354

# Submission time Handle Problem Language Result Execution time Memory
359354 2021-01-27T00:07:03 Z mjhmjh1104 Meteors (POI11_met) C++14
74 / 100
1616 ms 34688 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

long long tree[300006];

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

void update_fenwick(int x, long long v) {
    x++;
    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;
    long long l;
    long long r;
    long long m;
};

int n, m, q;
long long p[300006];
vector<pair<pair<int, int>, long long>> 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("%lld", p + i);
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int a, b;
        long long x;
        scanf("%d%d%lld", &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 < 25; 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) {
                long long sum = 0;
                for (auto &j: o[queries[k].q]) sum += query(j);
                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, updates[i].first.second, updates[i].second);
            else update(updates[i].first.first, m - 1, updates[i].second), update(0, updates[i].first.second, updates[i].second);
        }
        for (; k < n; k++) {
            long long sum = 0;
            for (auto &j: o[queries[k].q]) sum += query(j);
            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 >= 300000) puts("NIE");
        else printf("%lld\n", i.l + 1);
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
met.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~
met.cpp:51:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     for (int i = 0; i < n; i++) scanf("%lld", p + i);
      |                                 ~~~~~^~~~~~~~~~~~~~~
met.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
met.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         scanf("%d%d%lld", &a, &b, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9708 KB Output is correct
2 Correct 19 ms 9836 KB Output is correct
3 Correct 19 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9708 KB Output is correct
2 Correct 20 ms 9836 KB Output is correct
3 Correct 20 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 12128 KB Output is correct
2 Correct 274 ms 13604 KB Output is correct
3 Correct 188 ms 13180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 12896 KB Output is correct
2 Correct 215 ms 13028 KB Output is correct
3 Correct 280 ms 13664 KB Output is correct
4 Correct 76 ms 11620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 12220 KB Output is correct
2 Correct 296 ms 13800 KB Output is correct
3 Correct 232 ms 11232 KB Output is correct
4 Correct 189 ms 13152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 11872 KB Output is correct
2 Correct 245 ms 13152 KB Output is correct
3 Correct 146 ms 12000 KB Output is correct
4 Correct 259 ms 13916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 34688 KB Output is correct
2 Incorrect 906 ms 24156 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1551 ms 33736 KB Output is correct
2 Incorrect 899 ms 22612 KB Output isn't correct
3 Halted 0 ms 0 KB -