답안 #199786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199786 2020-02-03T11:23:06 Z Mercenary Sails (IOI07_sails) C++14
100 / 100
144 ms 2168 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;

int n;
ii a[maxn];
int bit[maxn];
int q(int x){
    int res = 0;
    for( ; x > 0 ; x &= x - 1){
        res += bit[x];
    }
    return res;
}
void u(int x , int val){
    for( ; x < maxn ; x += x & -x){
        bit[x]+=val;
    }
}
void u(int l , int r , int val){
    u(l,val);u(r+1,-val);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 0 ; i < n ; ++i)cin >> a[i].first >> a[i].second;
    sort(a , a + n);
    vector<int> v(1e5+5);
    iota(v.begin(),v.end(),1);
    for(int i = 0 ; i < n ; ++i){
        int h , k;tie(h,k) = a[i];
        int pivot = h - k + 1;
        int ft = lower_bound(v.begin(),v.begin()+h,pivot,[&](const int x , const int y){return q(x)>q(y);})-v.begin()+1;
        int lt = upper_bound(v.begin(),v.begin()+h,pivot,[&](const int x , const int y){return q(x)>q(y);})-v.begin()+1;
        u(lt,h,1);
        k -= h - lt + 1;
        u(ft,ft+k-1,1);
    }
    ll res = 0;
    for(int i = 1 ; i < maxn ; ++i){
        int tmp = q(i);
        res += (ll)tmp * (tmp - 1) / 2;
    }
    cout << res;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:43:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 7 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 764 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 760 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1016 KB Output is correct
2 Correct 34 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 1812 KB Output is correct
2 Correct 101 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 1912 KB Output is correct
2 Correct 111 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 1860 KB Output is correct
2 Correct 92 ms 2040 KB Output is correct