답안 #74975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74975 2018-09-07T19:14:50 Z Vardanyan 돌 무게 재기 (IZhO11_stones) C++14
0 / 100
2 ms 256 KB
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 100*1000+7;
int t[2][N];
void update(int num,int v,int s,int e,int l,int r){
    if(l>r) return;
    if(s == l && e == r){
        t[num][v]++;
        return;
    }
    int m = (s+e)/2;
    update(num,v*2,s,m,l,min(m,r));
    update(num,v*2+1,m+1,e,max(l,m+1),r);
    t[num][v] = t[num][v*2]+t[num][v*2+1];
}
int query(int num,int v,int s,int e,int l,int r){
    if(l>r) return 0;
    if(s == l && e == r) return t[num][v];
    int m = (s+e)/2;
    return query(num,v*2,s,m,l,min(m,r))+query(num,v*2+1,m+1,e,max(l,m+1),r);
}
int main(){
    int n;
    scanf("%d",&n);
    int qan1 = 0,qan2 = 0;
    long long val1 = 0,val2 = 0;
    for(int i = 1;i<=n;i++){
        int r,s;
        scanf("%d%d",&r,&s);
        if(s == 1){
            qan1++;
            update(1,1,1,n,r,r);
            val1+=query(2,1,1,n,1,r-1);
            val2+=(query(2,1,1,n,r+1,n));
        }
        else{
            qan2++;
            update(2,1,1,n,r,r);
            val2+=query(1,1,1,n,1,r-1);
            val1+=(query(1,1,1,n,r+1,n));
        }
      //  cout<<val1<<" "<<val2<<endl;
        bool f1 = false,f2 = false;
        if(qan1 == 0){
            printf("<\n");
            continue;
        }
        if(qan2 == 0){
            printf(">\n");
            continue;
        }
        if(qan1>=qan2){
            f1 = true;
            long long c = qan2;
            c*=(c+1);
            c/=2;
            if(val1<c) f1 = false;
        }
        if(qan2>=qan1){
            f2 = true;
            long long c = qan1;
            c*=(c+1);
            c/=2;
            if(val2<c) f2 = false;
        }
        if(f1){
            printf(">\n");
        }
        else if(f2){
            printf("<\n");
        }
        else{
            printf("?\n");
        }
    }
    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
stones.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&r,&s);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -