Submission #199786

#TimeUsernameProblemLanguageResultExecution timeMemory
199786MercenarySails (IOI07_sails)C++14
100 / 100
144 ms2168 KiB
#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 (stderr)

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);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...