제출 #1224588

#제출 시각아이디문제언어결과실행 시간메모리
1224588lkaterisInside information (BOI21_servers)C++20
0 / 100
3596 ms652 KiB
#include <iostream>
#include <utility>

using namespace std;


pair<int,int> seg[480005];
pair<int,int> lazy[480005];
int N,K;

void Build(int start=1,int ende=N,int ind=1) {
    if (start == ende) {
        seg[ind].first = start;
        seg[ind].second = start;
        return;
    }
    int mid=(start+ende)/2;

    Build(start,mid,ind*2);
    Build(mid+1,ende,ind*2 + 1);
    return;
}

void Update(int from, int to,int vall,int valr,int start=1,int ende=N,int ind=1) {
    if (start==from and ende==to) {
        lazy[ind].first += vall;
        lazy[ind].second += valr;
        return;
    }

    int mid=(start+ende)/2;
    if (to <= mid) Update(from,to,vall,valr,start,mid,ind*2);
    else if (mid < from) Update(from,to,vall,valr,mid+1,ende,ind*2 + 1);
    else {
        Update(from,mid,vall,valr,start,mid,ind*2);
        Update(mid+1,to,vall,valr,mid+1,ende,ind*2 + 1);
    }
    return;
}

pair<int,int> Query(int pos,int start=1,int ende=N,int ind=1) {
    if (start == ende) {
        seg[ind].first += lazy[ind].first;
        seg[ind].second += lazy[ind].second;
        lazy[ind] = {0,0};
        return seg[ind];
    }

    int mid=(start+ende)/2;

    seg[ind].first += lazy[ind].first;
    seg[ind].second += lazy[ind].second;

    lazy[ind*2].first += lazy[ind].first;
    lazy[ind*2].second += lazy[ind].second;

    lazy[ind*2 + 1].first += lazy[ind].first;
    lazy[ind*2 + 1].second += lazy[ind].second;
    lazy[ind] = {0,0};

    if (pos <= mid) return Query(pos,start,mid,ind*2);
    else return Query(pos,mid+1,ende,ind*2 + 1);
}


int main() {


    scanf("%d%d",&N,&K);

    Build();

    for(int q=1;q<=N+K-1;++q) {
        char t;
        scanf("\n%c",&t);
        if (t == 'S') {
            int a,b;
            scanf("%d%d",&a,&b);
            if (a > b) swap(a,b);
            pair<int,int> lra = Query(a);
            pair<int,int> lrb = Query(b);

            Update(lra.first,lra.second,0,1);
            Update(lrb.first,lrb.second,-1,0);
        }
        else if (t == 'Q') {
            int a,d;
            scanf("%d%d",&a,&d);
            pair<int,int> lrd = Query(d);

            if (lrd.first <= a and a <=lrd.second) printf("yes\n");
            else printf("no\n");

        }
        else if (t == 'C') {
            int d;
            scanf("%d",&d);
            pair<int,int> lrd = Query(d);

            printf("%d\n",lrd.second-lrd.first+1);
        }

    }


    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

servers.cpp: In function 'int main()':
servers.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d%d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~
servers.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         scanf("\n%c",&t);
      |         ~~~~~^~~~~~~~~~~
servers.cpp:78:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |             scanf("%d%d",&a,&b);
      |             ~~~~~^~~~~~~~~~~~~~
servers.cpp:88:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |             scanf("%d%d",&a,&d);
      |             ~~~~~^~~~~~~~~~~~~~
servers.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |             scanf("%d",&d);
      |             ~~~~~^~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...