#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T>>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
const int N=1e5+5;
vector<pair<int,int> > sails;
vector<int> minn(4*N),maxx(4*N),lazy(4*N);
void prop(int i)
{
minn[2*i]+=lazy[i];
minn[2*i+1]+=lazy[i];
maxx[2*i]+=lazy[i];
maxx[2*i+1]+=lazy[i];
lazy[2*i]+=lazy[i];
lazy[2*i+1]+=lazy[i];
lazy[i]=0;
}
void update(int i)
{
minn[i]=min(minn[2*i],minn[2*i+1]);
maxx[i]=max(maxx[2*i],maxx[2*i+1]);
}
void inc(int qs,int qe,int l=0,int r=N-1,int i=1)
{
if(qs>qe)
return;
if(qs>r||qe<l)
return;
if(qs<=l&&qe>=r)
{
lazy[i]++;
minn[i]++;
maxx[i]++;
return;
}
prop(i);
int m=(l+r)>>1;
inc(qs,qe,l,m,2*i);
inc(qs,qe,m+1,r,2*i+1);
update(i);
}
int get(int pos,int l=0,int r=N-1,int i=1)
{
if(l>pos||r<pos)
return 0;
if(l==pos&&r==pos)
return minn[i];
prop(i);
int m=(l+r)>>1;
return get(pos,l,m,2*i)+get(pos,m+1,r,2*i+1);
}
int getfirst(int vr,int l=0,int r=N-1,int i=1)
{
if(l==r)
return l;
prop(i);
int m=(l+r)>>1;
if(maxx[2*i]>=vr)
return getfirst(vr,l,m,2*i);
else
return getfirst(vr,m+1,r,2*i+1);
}
int getlast(int vr,int l=0,int r=N-1,int i=1)
{
if(l==r)
return l;
prop(i);
int m=(l+r)>>1;
if(minn[2*i+1]<=vr)
return getlast(vr,m+1,r,2*i+1);
else
return getlast(vr,l,m,2*i);
}
void add(int h,int k)
{
int start=N-h;
int koji=get(start+k-1);
int l=max(start,getfirst(koji)),r=getlast(koji);
int ostalo=start+k-l;
inc(start,l-1);
inc(r-ostalo+1,r);
}
ll getres(int l=0,int r=N-1,int i=1)
{
if(l==r)
return (ll)minn[i]*(minn[i]-1)/2;
prop(i);
int m=(l+r)>>1;
return getres(l,m,2*i)+getres(m+1,r,2*i+1);
}
int main()
{
int n;
scanf("%i",&n);
for(int i=0;i<n;i++)
{
int a,b;
scanf("%i %i",&a,&b);
sails.pb({a,b});
}
sort(all(sails));
for(auto p:sails)
st.add(p.f,p.s);
printf("%lld\n",st.getres());
return 0;
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:126:9: error: 'st' was not declared in this scope
st.add(p.f,p.s);
^~
sails.cpp:126:9: note: suggested alternative: 's'
st.add(p.f,p.s);
^~
s
sails.cpp:127:21: error: 'st' was not declared in this scope
printf("%lld\n",st.getres());
^~
sails.cpp:127:21: note: suggested alternative: 's'
printf("%lld\n",st.getres());
^~
s
sails.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
sails.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&a,&b);
~~~~~^~~~~~~~~~~~~~~