제출 #157932

#제출 시각아이디문제언어결과실행 시간메모리
157932PeppaPig이상한 기계 (APIO19_strange_device)C++14
35 / 100
883 ms69104 KiB
#include <bits/stdc++.h>

#define long long long
#define pii pair<long, long>
#define x first
#define y second

using namespace std;

const int N = 1e6+5;

int n;
long A, B, cyc;
vector<pii> v;

int main() {
    scanf("%d %lld %lld", &n, &A, &B);
    cyc = A / __gcd(B+1, A);
    cyc *= B;

    for(int i = 1; i <= n; i++) {
        long l, r;
        scanf("%lld %lld", &l, &r);
        if(r - l + 1 >= cyc) v.emplace_back(0, 1), v.emplace_back(cyc, -1);
        else {
            l %= cyc, r %= cyc;
            v.emplace_back(l, 1);
            v.emplace_back(r + 1, -1); 
            if(l > r) {
                v.emplace_back(0, 1);
                v.emplace_back(cyc, -1);
            }
        }
    }
    sort(v.begin(), v.end());
    long ans = 0;
    for(int i = 0, cnt = 0; i < v.size(); ) {
        int j = i;
        for( ; v[i].x == v[j].x; j++) cnt += v[j].y;
        if(cnt) ans += v[j].x - v[i].x;
        i = j;
    }
    printf("%lld\n", ans);

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

strange_device.cpp: In function 'int main()':
strange_device.cpp:37:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0, cnt = 0; i < v.size(); ) {
                             ~~^~~~~~~~~~
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %lld", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...