Submission #440428

#TimeUsernameProblemLanguageResultExecution timeMemory
440428DJeniUpStrange Device (APIO19_strange_device)C++17
100 / 100
1896 ms63064 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,pairll>pairllll;
typedef long double ld;
typedef pair<ll,string>pairls;

#define INF 1000000000000007
#define pb push_back
#define fr first
#define sc second

ll n,m,g;
ull a,b,k;

struct D{
    ll x,y;
}d[1000007],t[4000007];

bool mcp(D d1, D d2){
    return d1.x<d2.x;
}

int main()
{
    cin>>n>>a>>b;
    k=__gcd(a,b+1);
    k=a/k;
    k*=b;
    for(int i=1;i<=n;i++){
        cin>>d[i].x>>d[i].y;
        d[i].y++;
        if(d[i].y-d[i].x>=k){
            m++;
            t[m]={0,1};
            m++;
            t[m]={k,-1};
        }else{
            d[i].x%=k;
            d[i].y%=k;
            m++;
            if(d[i].x<=d[i].y){
                m++;
                t[m]={d[i].x,1};
                m++;
                t[m]={d[i].y,-1};
            }else{
                m++;
                t[m]={d[i].x,1};
                m++;
                t[m]={d[i].y,-1};
                m++;
                t[m]={0,1};
                m++;
                t[m]={k,-1};
            }
        }
    }

    m++;
    t[m].x=k;
    sort(t+1,t+1+m,mcp);
    ll r=0;
    ll h=0;
    t[0].x=0;
    for(int i=1;i<=m;i++){
        if(h>0){
            r+=(t[i].x-t[i-1].x);
        }
        h+=(t[i].y);
    }
    cout<<r<<endl;

    return 0;
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:38:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   38 |         if(d[i].y-d[i].x>=k){
      |            ~~~~~~~~~~~~~^~~
strange_device.cpp:42:19: warning: narrowing conversion of 'k' from 'ull' {aka 'long long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
   42 |             t[m]={k,-1};
      |                   ^
strange_device.cpp:60:23: warning: narrowing conversion of 'k' from 'ull' {aka 'long long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
   60 |                 t[m]={k,-1};
      |                       ^
#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...