Submission #371227

# Submission time Handle Problem Language Result Execution time Memory
371227 2021-02-26T07:47:11 Z uacoder123 Sails (IOI07_sails) C++14
100 / 100
451 ms 6612 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <ii,lli> iii;
typedef vector <lli> vi;
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
lli segt[100001*4],lazy[4*100001],n;
void up(lli node,lli l,lli r,lli s,lli e)
{
  if(lazy[node]!=0)
  {
    segt[node]+=lazy[node]*(r-l+1);
    if(l!=r)
    {
      lazy[2*node+1]+=lazy[node];
      lazy[2*node+2]+=lazy[node];
    }
    lazy[node]=0;
  }
  if(l>e||r<s)
    return;
  lli m=(l+r)/2;
  if(l>=s&&r<=e)
  {
    segt[node]+=(r-l+1);
    if(l!=r)
    {
      lazy[2*node+1]+=1;
      lazy[2*node+2]+=1;
    }
    return;
  }
  up(2*node+1,l,m,s,e);
  up(2*node+2,m+1,r,s,e);
  segt[node]=segt[2*node+1]+segt[2*node+2];
}
lli qu(lli node,lli l,lli r,lli in)
{
  if(lazy[node]!=0)
  {
    segt[node]+=lazy[node]*(r-l+1);
    if(l!=r)
    {
      lazy[2*node+1]+=lazy[node];
      lazy[2*node+2]+=lazy[node];
    }
    lazy[node]=0;
  }
  if(l==r)
    return segt[node];
  lli m=(l+r)/2;
  if(in<=m)
    return qu(2*node+1,l,m,in);
  else
    return qu(2*node+2,m+1,r,in);
}
lli te(lli val)
{
  lli u=100000,l=0,ans=100000;
  while(u>=l)
  {
    lli m=(l+u)/2,v;
    v=qu(0,0,100000,m);
    if(v>val)
      l=m+1;
    else
    {
      u=m-1;
      ans=m;
    }
  }
  return ans;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n;
  ii arr[n];
  for(lli i=0;i<n;++i)
    cin>>arr[i].F>>arr[i].S;
  sort(arr,arr+n);
  for(lli i=0;i<n;++i)
  {
    lli h=arr[i].F,no=arr[i].S,v,f,s;
    h--;
    if(no==0)
      continue;
    v=qu(0,0,100000,h-(no-1));
    f=te(v);
    if(v>qu(0,0,100000,h))
    {
      s=te(v-1);
      up(0,0,100000,s,h);
    }
    else
      s=h+1;
    up(0,0,100000,f,f+(s-(h-(no-1)))-1);
  }
  lli ans=0;
  for(lli i=0;i<100000;++i)
  {
    lli c=qu(0,0,100000,i);
    if(c>0)
    ans+=(c*(c-1))/2;
  }
  cout<<ans<<endl;
  return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 11 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 620 KB Output is correct
2 Correct 15 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1772 KB Output is correct
2 Correct 111 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 5740 KB Output is correct
2 Correct 302 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 5868 KB Output is correct
2 Correct 150 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 6272 KB Output is correct
2 Correct 272 ms 4332 KB Output is correct