답안 #240367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240367 2020-06-19T14:05:40 Z valerikk 이상한 기계 (APIO19_strange_device) C++14
0 / 100
5000 ms 131804 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int get_union(vector<pair<int, int>> seg) {
    vector<pair<int, int>> events;
    for (auto [l, r] : seg) {
        events.emplace_back(l, 1);
        events.emplace_back(r + 1, -1);
    }
    sort(events.begin(), events.end());
    int res = 0, cnt = 0;
    for (int i = 0; i + 1 < events.size(); i++) {
        cnt += events[i].second;
        if (cnt > 0)
            res += events[i + 1].first - events[i].first;
    }
    return res;

}

int gcd(int a, int b) {
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

struct Event {
    int x, type, pl, pr;

    Event() {}
    Event(int x, int type, int pl, int pr) : x(x), type(type), pl(pl), pr(pr) {}
};

bool operator<(Event a, Event b) {
    return a.x < b.x || (a.x == b.x && -a.type < -b.type);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    int p = a / gcd(a, b + 1);
    vector<Event> events;
    auto add = [&] (int l, int r, int pl, int pr) {
        events.emplace_back(l, 1, pl, pr);
        events.emplace_back(r + 1, -1, pl, pr);
    };
    while (n--) {
        int l, r;
        cin >> l >> r;
        int L = l / b, R = r / b;
        if (L == R)
            add(l % b, r % b, L % p, R % p);
        else {
            int inside = R - L - 1;
            if (inside > 0)
                add(0, b - 1, (L + 1) % p, (R - 1) % p);
            add(l % b, b - 1, L % p, L % p);
            add(0, r % b, R % p, R % p);
        }
    }
    sort(events.begin(), events.end());
    multiset<pair<int, int>> seg;
    ll ans = 0;
    for (int i = 0; i + 1 < events.size(); i++) {
        if (events[i].type == 1)
            seg.insert({events[i].pl, events[i].pr});
        else
            seg.erase(seg.find({events[i].pl, events[i].pr}));
        vector<pair<int, int>> to_union;
        for (auto [l, r] : seg) {
            if (l <= r)
                to_union.emplace_back(l, r);
            else {
                to_union.emplace_back(0, r);
                to_union.emplace_back(l, p - 1);
            }
        }
        int diff = events[i + 1].x - events[i].x;
        if (diff != 0)
            ans += (ll) diff * get_union(to_union);
    }
    cout << ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int get_union(std::vector<std::pair<int, int> >)':
strange_device.cpp:8:15: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     for (auto [l, r] : seg) {
               ^
strange_device.cpp:14:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i + 1 < events.size(); i++) {
                     ~~~~~~^~~~~~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:70:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i + 1 < events.size(); i++) {
                     ~~~~~~^~~~~~~~~~~~~~~
strange_device.cpp:76:19: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         for (auto [l, r] : seg) {
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 1675 ms 2160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 5044 ms 512 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 5053 ms 131804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 5053 ms 131804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 5053 ms 131804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Execution timed out 5049 ms 9108 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 1675 ms 2160 KB Output isn't correct
3 Halted 0 ms 0 KB -