Submission #199785

#TimeUsernameProblemLanguageResultExecution timeMemory
199785MercenarySails (IOI07_sails)C++14
5 / 100
64 ms1888 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; } int b(int r , int val){ int pos = 0; for(int i = 16 ; i >= 0 ; --i){ if(pos + (1 << i) <= r && bit[pos + (1 << i)] < val){ val -= bit[pos + (1 << i)];pos += (1 << i); } } return pos+1; } 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,greater<ii>()); for(int i = 0 ; i < n ; ++i){ int h , k;tie(h,k) = a[i]; int val = q(k); int ft = b(h,val); int lt = min(h,b(h,val+1)-1); int tmp = (k - ft + 1); u(lt-tmp+1,lt,1); k -= tmp; u(ft-k,ft-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:51: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:52: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...