답안 #585612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585612 2022-06-29T06:17:48 Z 반딧불(#8385) MP3 Player (CEOI10_mp3player) C++17
60 / 100
173 ms 11580 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Node{
    ll ax, ay, bx, by;
    Node(){}
    Node(ll ax, ll ay, ll bx, ll by): ax(ax), ay(ay), bx(bx), by(by){
        assert(ax-ay==bx-by);
    }

    ll calc(ll x){
        if(x<=ax) return ay;
        if(x>=bx) return by;
        return by-(bx-x);
    }

    Node operator+(Node &r){
        if(by <= r.ax) return Node(0, r.ay, 0, r.ay);
        else if(r.bx <= ay) return Node(0, r.by, 0, r.by);
        else if(ay <= r.ax && by <= r.bx) return Node(ax + (r.ax - ay), r.ay, bx, r.calc(by));
        else if(r.ax <= ay && r.bx <= by) return Node(ax, r.calc(ay), bx - (by - r.bx), r.by);
        else if(r.ax <= ay && by <= r.bx) return Node(ax, r.calc(ay), bx, r.calc(by));
        else return Node(ax + (r.ax - ay), r.ay, bx - (by - r.bx), r.by);
    }
};

struct segTree{
    Node tree[400002];

    void init(int i, int l, int r, Node node){
        tree[i] = node;
        if(l==r) return;
        int m = (l+r)>>1;
        init(i*2, l, m, node);
        init(i*2+1, m+1, r, node);
    }

    void update(int i, int l, int r, int x, Node node){
        if(l==r){
            tree[i] = node;
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) update(i*2, l, m, x, node);
        else update(i*2+1, m+1, r, x, node);
        tree[i] = tree[i*2] + tree[i*2+1];
    }
} tree;

int n; ll k, goal;
bool op[100002];
ll arr[100002];
vector<pair<ll, int> > vec;
ll ans, ansV;

int main(){
    scanf("%d %lld %lld", &n, &k, &goal);
    ansV = goal;
    for(int i=1; i<=n; i++){
        char c;
        scanf(" %c %lld", &c, &arr[i]);
        if(c == '+') op[i] = 1;
    }
    tree.init(1, 1, n, Node(0, 0, k, k));
    for(int i=1; i<n; i++) vec.push_back(make_pair(arr[i+1]-arr[i], i+1));
    sort(vec.begin(), vec.end());
    for(int i=0; i<(int)vec.size(); i++){
        int j = i;
        while(j < (int)vec.size()-1 && vec[j+1].first == vec[i].first) j++;
        for(int x=i; x<=j; x++){
            tree.update(1, 1, n, vec[x].second, op[vec[x].second] ? Node(0, 1, k-1, k) : Node(1, 0, k, k-1));
        }
        Node tmp = tree.tree[1];
        if(goal < tmp.ay || tmp.by < goal) continue;
        ans = (j+1 == (int)vec.size() ? -1 : vec[j+1].first - 1);
        if(goal == tmp.ay) ansV = tmp.ax;
        else if(goal == tmp.by) ansV = k;
        else ansV = tmp.bx - (tmp.by - goal);
        i=j;
    }
    if(ans == -1){
        printf("infinity");
    }
    else printf("%lld %lld", ans, ansV);
}

Compilation message

mp3player.cpp: In function 'int main()':
mp3player.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     scanf("%d %lld %lld", &n, &k, &goal);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mp3player.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf(" %c %lld", &c, &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 70 ms 696 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 17 ms 480 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 3268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 5964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 11476 KB Output is correct
2 Correct 69 ms 11532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 11580 KB Output is correct
2 Correct 58 ms 11456 KB Output is correct