답안 #403370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403370 2021-05-13T05:53:25 Z Hazem 이상한 기계 (APIO19_strange_device) C++14
0 / 100
3 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 1e6+10;
const int M = 200;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

pair<LL,LL>p[N];
vector<pair<LL,LL>>vec;

struct node{

    node *l,*r;
    LL sum = 0;
    int lazy = 0;
    node():l(NULL),r(NULL){};
};

void push(node * &v,LL tl,LL tr){

    if(v==NULL||!v->lazy)return ;
    v->sum = tr-tl+1;

    if(tl!=tr){
        
        if(v->l==NULL)v->l = new node();
        if(v->r==NULL)v->r = new node();

        v->l->lazy = 1;
        v->r->lazy = 1;    
    }
    v->lazy = 0;
}

void update(node * &v,LL tl,LL tr,LL l,LL r){

    push(v,tl,tr);

    if(tl>r||tr<l)
        return ;
    
    if(v==NULL) v = new node();

    if(tl>=l&&tr<=r){
        v->lazy = 1;
        push(v,tl,tr);
        return ;
    }

    LL mid = (tl+tr)/2;
    update(v->l,tl,mid,l,r);
    update(v->r,mid+1,tr,l,r);
    v->sum = (v->l==NULL?0:v->l->sum)+(v->r==NULL?0:v->r->sum);
}

node *root;

int main(){

    //freopen("out.txt","w",stdout);

    LL n,a,b,Len;
    scanf("%lld%lld%lld",&n,&a,&b);

    if(log(a)+log(b)>=log(LLONG_MAX))    
        Len = LINF;
    else 
        Len = a*b;

    bool q = 0;
    for(int i=1;i<=n;i++){

        scanf("%lld%lld",&p[i].F,&p[i].S);
        q |= p[i].S-p[i].F+1>=Len;

        p[i].F %= Len;p[i].S %= Len;
        
        if(p[i].S>=p[i].F)
            vec.push_back({p[i].F,p[i].S});
        else 
            vec.push_back({p[i].F,Len-1}),vec.push_back({0,p[i].S});
    }

    sort(vec.begin(),vec.end());
    
    LL l = 0,r = -1,ans = 0;
    vec.push_back({LINF,LINF});

    for(int i=0;i<vec.size();i++){
        
        if(vec[i].F>r)
            ans += r-l+1,l = vec[i].F,r = vec[i].S;
        else 
            r = vec[i].S;
    }

    assert(Len!=1);    
    printf("%lld\n",q?Len:ans);
}   

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(int i=0;i<vec.size();i++){
      |                 ~^~~~~~~~~~~
strange_device.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%lld%lld%lld",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         scanf("%lld%lld",&p[i].F,&p[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -