답안 #197740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197740 2020-01-22T17:45:43 Z Andrei_Cotor 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1094 ms 68984 KB
//la o perioada de B in dreapta, stanga creste cu B+1
#include<iostream>
#include<algorithm>
#define INF 1000000000000000005LL

using namespace std;

typedef struct event
{
    long long poz;
    int tip;
} EVENT;

bool cmp(EVENT a, EVENT b)
{
    if(a.poz!=b.poz)
        return a.poz<b.poz;
    else
        return a.tip>b.tip;
}

EVENT Ev[4000005];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

    int n;
    long long a,b;
    cin>>n>>a>>b;

    long long d=__gcd(a,b+1);
    long long nr=a/d;  //de cate ori trb sa adun B+1 pt a obtine un multiplu de A, in stanga

    long long per=0;
    if(nr<=INF/b)
        per=nr*b;
    else
        per=INF;

    int nrev=0;
    for(int i=1; i<=n; i++)
    {
        long long x,y;
        cin>>x>>y;

        if(y-x>=per)
            y=x+per-1;

        x%=per;
        y%=per;

        if(x<=y)
        {
            Ev[++nrev]={x,1};
            Ev[++nrev]={y,-1};
        }
        else
        {
            Ev[++nrev]={0,1};
            Ev[++nrev]={y,-1};
            Ev[++nrev]={x,1};
            Ev[++nrev]={per-1,-1};
        }
    }

    sort(Ev+1,Ev+nrev+1,cmp);

    int nractiv=0;
    long long rez=0;
    for(int i=1; i<=nrev; i++)
    {
        long long poz=Ev[i].poz;
        while(i<=nrev && Ev[i].poz==poz && Ev[i].tip==1)
        {
            nractiv++;
            i++;
        }

        if(nractiv>0)
            rez++;

        while(i<=nrev && Ev[i].poz==poz && Ev[i].tip==-1)
        {
            nractiv--;
            i++;
        }

        i--;

        if(nractiv>0)
        {
            if(i<nrev)
                rez=rez+(Ev[i+1].poz-Ev[i].poz-1);
            else
                rez=rez+(per-Ev[i].poz-1);
        }
    }

    cout<<rez<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1016 KB Output is correct
17 Correct 98 ms 7160 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 563 ms 32248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 870 ms 32784 KB Output is correct
3 Correct 903 ms 32732 KB Output is correct
4 Correct 885 ms 68920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 870 ms 32784 KB Output is correct
3 Correct 903 ms 32732 KB Output is correct
4 Correct 885 ms 68920 KB Output is correct
5 Correct 10 ms 376 KB Output is correct
6 Correct 923 ms 68892 KB Output is correct
7 Correct 888 ms 68896 KB Output is correct
8 Correct 884 ms 64348 KB Output is correct
9 Correct 1094 ms 68984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 870 ms 32784 KB Output is correct
3 Correct 903 ms 32732 KB Output is correct
4 Correct 885 ms 68920 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 86 ms 7236 KB Output is correct
7 Correct 93 ms 7332 KB Output is correct
8 Correct 105 ms 7160 KB Output is correct
9 Correct 98 ms 7160 KB Output is correct
10 Correct 79 ms 7192 KB Output is correct
11 Correct 86 ms 7160 KB Output is correct
12 Correct 77 ms 7288 KB Output is correct
13 Correct 96 ms 7232 KB Output is correct
14 Correct 82 ms 7196 KB Output is correct
15 Correct 98 ms 7160 KB Output is correct
16 Correct 95 ms 7288 KB Output is correct
17 Correct 85 ms 7160 KB Output is correct
18 Correct 911 ms 63960 KB Output is correct
19 Correct 853 ms 68792 KB Output is correct
20 Correct 1053 ms 68752 KB Output is correct
21 Correct 101 ms 7284 KB Output is correct
22 Correct 77 ms 7288 KB Output is correct
23 Correct 224 ms 23676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 95 ms 7260 KB Output is correct
3 Correct 95 ms 7160 KB Output is correct
4 Correct 1060 ms 33412 KB Output is correct
5 Correct 97 ms 7160 KB Output is correct
6 Correct 103 ms 7160 KB Output is correct
7 Correct 97 ms 7284 KB Output is correct
8 Correct 97 ms 7160 KB Output is correct
9 Correct 91 ms 7160 KB Output is correct
10 Correct 98 ms 7160 KB Output is correct
11 Correct 94 ms 7288 KB Output is correct
12 Correct 86 ms 7268 KB Output is correct
13 Correct 99 ms 7276 KB Output is correct
14 Correct 1010 ms 33244 KB Output is correct
15 Correct 100 ms 7160 KB Output is correct
16 Correct 825 ms 68856 KB Output is correct
17 Correct 884 ms 68448 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1016 KB Output is correct
17 Correct 98 ms 7160 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 563 ms 32248 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 870 ms 32784 KB Output is correct
31 Correct 903 ms 32732 KB Output is correct
32 Correct 885 ms 68920 KB Output is correct
33 Correct 10 ms 376 KB Output is correct
34 Correct 923 ms 68892 KB Output is correct
35 Correct 888 ms 68896 KB Output is correct
36 Correct 884 ms 64348 KB Output is correct
37 Correct 1094 ms 68984 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 86 ms 7236 KB Output is correct
40 Correct 93 ms 7332 KB Output is correct
41 Correct 105 ms 7160 KB Output is correct
42 Correct 98 ms 7160 KB Output is correct
43 Correct 79 ms 7192 KB Output is correct
44 Correct 86 ms 7160 KB Output is correct
45 Correct 77 ms 7288 KB Output is correct
46 Correct 96 ms 7232 KB Output is correct
47 Correct 82 ms 7196 KB Output is correct
48 Correct 98 ms 7160 KB Output is correct
49 Correct 95 ms 7288 KB Output is correct
50 Correct 85 ms 7160 KB Output is correct
51 Correct 911 ms 63960 KB Output is correct
52 Correct 853 ms 68792 KB Output is correct
53 Correct 1053 ms 68752 KB Output is correct
54 Correct 101 ms 7284 KB Output is correct
55 Correct 77 ms 7288 KB Output is correct
56 Correct 224 ms 23676 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 95 ms 7260 KB Output is correct
59 Correct 95 ms 7160 KB Output is correct
60 Correct 1060 ms 33412 KB Output is correct
61 Correct 97 ms 7160 KB Output is correct
62 Correct 103 ms 7160 KB Output is correct
63 Correct 97 ms 7284 KB Output is correct
64 Correct 97 ms 7160 KB Output is correct
65 Correct 91 ms 7160 KB Output is correct
66 Correct 98 ms 7160 KB Output is correct
67 Correct 94 ms 7288 KB Output is correct
68 Correct 86 ms 7268 KB Output is correct
69 Correct 99 ms 7276 KB Output is correct
70 Correct 1010 ms 33244 KB Output is correct
71 Correct 100 ms 7160 KB Output is correct
72 Correct 825 ms 68856 KB Output is correct
73 Correct 884 ms 68448 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 7 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 9 ms 1016 KB Output is correct
80 Correct 1070 ms 68816 KB Output is correct
81 Correct 1075 ms 63964 KB Output is correct
82 Correct 1016 ms 68584 KB Output is correct
83 Correct 1010 ms 68908 KB Output is correct
84 Correct 1024 ms 63888 KB Output is correct
85 Correct 1022 ms 68684 KB Output is correct
86 Correct 221 ms 23672 KB Output is correct
87 Correct 2 ms 376 KB Output is correct