답안 #544208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544208 2022-04-01T11:01:08 Z Victor 이상한 기계 (APIO19_strange_device) C++17
0 / 100
1 ms 340 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

struct Node {
    ll sum=0,lo,hi,mset=INF;
    Node *l=0,*r=0;

    Node(ll L,ll R) : lo(L),hi(R) {}

    void set(ll L,ll R,ll x) {
        if(hi<=L||R<=lo) return;

        if(L<=lo&&hi<=R) {
            mset=x;
            sum=(hi-lo)*mset;

        } else {
            push();
            l->set(L,R,x),r->set(L,R,x);
            sum=l->sum+r->sum;
        }
    }

    void push() {
        if(!l) {
            ll mid=(lo+hi)/2;
            l=new Node(lo,mid);
            r=new Node(mid,hi);
        }

        if(mset!=INF) {
            l->set(lo,hi,mset),r->set(lo,hi,mset);
            mset=INF;
        }
    }
};

int n;
ll A,B,len;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    cin>>n>>A>>B;
    ll x=A/__gcd(A,B+1);
    if(log10(x)+log10(B)>18) len=ll(1e18);
    else len=B*x;

    debug(len);
    Node segtree(0,len);
    while(n--) {
        ll lo,hi;
        cin>>lo>>hi;
        ++hi;

        if(hi-lo>=len) segtree.set(0,len,1);
        else {
            ll start=lo%len,take=min(hi-lo,(len-start)%len);

            //cout<<"start = "<<start<<" stop = "<<start+take<<endl;

            segtree.set(start,start+take,1);

            start=0;
            take=(hi-lo)-take;

            //cout<<"start = "<<start<<" stop = "<<start+take<<endl;

            segtree.set(start,start+take,1);
        }
        //cout<<endl;
    }

    cout<<segtree.sum<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -