답안 #240380

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

#define sz(x) ((int) (x).size())

typedef long long ll;

int calc(multiset<pair<ll, ll>> seg) {
    vector<pair<ll, ll>> events;
    for (auto [l, r] : seg) {
        events.emplace_back(l, 1);
        events.emplace_back(r + 1, -1);
    }
    sort(events.begin(), events.end());
    ll res = 0;
    int 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 {
    ll x; 
    int type; 
    ll pl, pr;

    Event() {}
    Event(ll x, int type, ll pl, ll 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);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll p = a / gcd(a, b + 1);
    vector<Event> events;
    auto add = [&] (ll l, ll r, ll pl, ll pr) {
        events.emplace_back(l, 1, pl, pr);
        events.emplace_back(r + 1, -1, pl, pr);
    };
    auto add_safe = [&] (ll l, ll r, ll pl, ll pr) {
        if (pl > pr) {
            add(l, r, 0, pr);
            add(l, r, pl, p - 1);
        } else
            add(l, r, pl, pr);
    };
    while (n--) {
        ll l, r;
        cin >> l >> r;
        ll L = l / b, R = r / b;
        if (L == R)
            add_safe(l % b, r % b, L % p, R % p);
        else {
            if (L + 1 < R)
                add_safe(0, b - 1, (L + 1) % p, (R - 1) % p);
            add_safe(l % b, b - 1, L % p, L % p);
            add_safe(0, r % b, R % p, R % p);
        }
    }
    sort(events.begin(), events.end());
    multiset<pair<ll, ll>> seg;
    ll ans = 0;
    for (int i = 0; i + 1 < sz(events); ++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}));
        ll diff = events[i + 1].x - events[i].x;
        if (diff != 0)
            ans += calc(seg) * diff;
    }
    cout << ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int calc(std::multiset<std::pair<long long int, long long int> >)':
strange_device.cpp:10:15: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     for (auto [l, r] : seg) {
               ^
strange_device.cpp:17:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i + 1 < events.size(); i++) {
                     ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 23 ms 1916 KB Output is correct
3 Correct 22 ms 1916 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 304 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 24 ms 1916 KB Output is correct
17 Correct 90 ms 10196 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 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 4 ms 384 KB Output is correct
2 Correct 23 ms 1024 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
4 Correct 63 ms 640 KB Output is correct
5 Runtime error 1663 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 1211 ms 240888 KB Output is correct
3 Runtime error 1819 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 1211 ms 240888 KB Output is correct
3 Runtime error 1819 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 1211 ms 240888 KB Output is correct
3 Runtime error 1819 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 1815 ms 10208 KB Output is correct
3 Execution timed out 5064 ms 10216 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 23 ms 1916 KB Output is correct
3 Correct 22 ms 1916 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 304 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 24 ms 1916 KB Output is correct
17 Correct 90 ms 10196 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Incorrect 5 ms 384 KB Output isn't correct
23 Halted 0 ms 0 KB -