답안 #371225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371225 2021-02-26T07:35:34 Z uacoder123 Sails (IOI07_sails) C++14
15 / 100
385 ms 7276 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];
    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]+=(m-l+1);
      lazy[2*node+2]+=(r-(m+1)+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];
    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;
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 364 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 364 KB Output is correct
2 Incorrect 8 ms 620 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 4460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 5228 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 184 ms 3820 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 262 ms 6764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 168 ms 6892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 385 ms 7276 KB Output isn't correct
2 Halted 0 ms 0 KB -