답안 #1011180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011180 2024-06-30T04:24:50 Z doducanh Sails (IOI07_sails) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define h first
#define k second
const int maxn=1e5;
pair<int,int>a[maxn+7];
int dem[maxn+7];
int n;
struct BIT{
    int n;
    vector<int>t;
    BIT(){}
    BIT(int n):n(n),t(n+7,0){}
    void up(int x,int val){
        for(;x<=n;x+=(x&(-x)))t[x]+=val;
    }
    int get(int x){
        int ans=0;
        for(;x;x-=(x&(-x)))ans+=t[x];
        return ans;
    }
};
main()
{
    freopen("sail.inp","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].h>>a[i].k;
    sort(a+1,a+n+1);
    BIT t(a[n].h);
//    for(int i=1;i<=n;i++){
//        cout<<a[i].h<<" "<<a[i].k<<"\n";
//    }
    for(int i=1;i<=n;i++){

        int h=a[i].h,k=a[i].k;
        int val=t.get(h-k);
        int l=1,r=h;
        int res=1;
        while(l<=r){
            int m=(l+r)/2;
            if(t.get(m)<=val){
                res=m;
                r=m-1;
            }
            else l=m+1;
        }
        int left=res;
        l=1,r=h;
        res=h+1;
        while(l<=r){
            int m=(l+r)/2;
            if(t.get(m)>=val){
                res=m;
                l=m+1;
            }
            else r=m-1;
        }
        int right=res;
        if(h==k)right=0;
        t.up(right+1,1);
        t.up(h+1,-1);
        t.up(left,1);
        t.up(left+(k-(h-right)),-1);
    }
    int ans=0;
    for(int i=1;i<=a[n].h;i++){
        int x=t.get(i);
        ans+=(x)*(x-1)/2;
    }
    cout<<ans;
    return 0;
}

Compilation message

sails.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
sails.cpp: In function 'int main()':
sails.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("sail.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -