Submission #876522

#TimeUsernameProblemLanguageResultExecution timeMemory
876522MarwenElarbiSails (IOI07_sails)C++17
0 / 100
74 ms8736 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define vi vector<int> #define ve vector #define ll long long #define vl vector<ll> #define vll vector<pair<ll,ll>> #define onbit __builtin_popcount #define ii pair<int,int> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e18 #define eps 1e-7 #define eps1 1e-2 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 1e5+5 using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const ll MOD = 1e9+7; const int nax = 2e5+5; const int MAX_VAL = 1e6+1; double PI=3.14159265359; int arx[8]={1,0,0,-1,-1,-1, 1, 1}; int ary[8]={0,1,-1, 0, 1,-1,-1, 1}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } vector<ii> tab; ii segtree[nax*4]; ii lazy[nax*4]; void build(int pos,int l,int r) { if (l==r){ segtree[pos]={0,l}; return; } int mid=(r+l)/2; build(pos*2+1,l,mid); build(pos*2+2,mid+1,r); if (segtree[pos*2+2].fi<=segtree[pos*2+1].fi) segtree[pos]=segtree[pos*2+2]; else segtree[pos]=segtree[pos*2+1]; return; } void expand(int pos) { if (lazy[pos].fi==0) return; segtree[pos*2+1]=max(segtree[pos*2+1],lazy[pos]); segtree[pos*2+2]=max(segtree[pos*2+2],lazy[pos]); lazy[pos*2+1]=max(lazy[pos*2+1],lazy[pos]); lazy[pos*2+2]=max(lazy[pos*2+2],lazy[pos]); lazy[pos].fi=lazy[pos].se=0; } void update(int pos,int l,int r,int left,int right) { if (l>r||r<left||l>right) return; if (l>=left&&r<=right){ segtree[pos].fi++; lazy[pos].fi++; lazy[pos].se=segtree[pos].se; return; } expand(pos); int mid=(r+l)/2; update(pos*2+1,l,mid,left,right); update(pos*2+2,mid+1,r,left,right); if (segtree[pos*2+2].fi<=segtree[pos*2+1].se) segtree[pos]=segtree[pos*2+2]; else segtree[pos]=segtree[pos*2+1]; return; } ii query(int pos,int l,int r,int index) { if (l==r){ return segtree[pos]; } int mid=(r+l)/2; expand(pos); if (index<=mid) return query(pos*2+1,l,mid,index); else return query(pos*2+2,mid+1,r,index); } int main(){ optimise; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ //setIO("boards"); int n; cin>>n; tab.resize(n); int h=0; for (int i = 0; i < n; ++i) { cin>>tab[i].fi>>tab[i].se; h=max(h,tab[i].fi); } build(0,0,h-1); sort(tab.begin(),tab.end(),greater<>()); for (int i = 0; i < n; ++i) { ii cur=tab[i]; ii x=segtree[0]; //cout <<"hey"<<x.fi<<" "<<x.se<<endl; int ne=min(x.se,cur.fi-1); if (ne>=cur.se-1){ //cout <<x.se-cur.se<<" "<<x.se-1<<endl; update(0,0,h-1,ne-cur.se,ne-1); }else{ update(0,0,h-1,0,ne-1); update(0,0,h-1,cur.fi-x.se-1,cur.fi-1); } } ll ans=0; for (int i = 0; i <= h; ++i) { ii x=query(0,0,h-1,i); ans+=(x.fi*(x.fi-1))/2; } cout <<ans<<endl; }

Compilation message (stderr)

sails.cpp: In function 'void setIO(std::string)':
sails.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".out").c_str(), "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...