Submission #7428

# Submission time Handle Problem Language Result Execution time Memory
7428 2014-08-05T06:33:00 Z gs13068 수족관 3 (KOI13_aqua3) C++
100 / 100
168 ms 19832 KB
#include<cstdio>
#include<set>
#include<algorithm>

#define OFFSET 262144

struct tree
{
  int x;
  int y;
} tr[600000];

int x[200000];
int y[200000];
int z[200000];

inline void init(){int i;for(i=0;i<OFFSET<<1;i++){tr[i].x=1e9;tr[i].y=i-OFFSET;}}
inline void update(int x,int y){x+=OFFSET;for(tr[x].x=y;x;x>>=1)if(tr[x>>1].x>y){tr[x>>1].x=y;tr[x>>1].y=tr[x].y;}}
inline int where(int x,int y){int r=1e9,ri;for(x+=OFFSET,y+=OFFSET;x<=y;x=(x+1)>>1,y=(y-1)>>1){if(tr[x].x<r){r=tr[x].x;ri=tr[x].y;}if(tr[y].x<r){r=tr[y].x;ri=tr[y].y;}}return ri;}

std::multiset<long long> S;
std::multiset<long long>::iterator it;

long long dfs(int l,int r,int d)
{
  if(l>r)return 0LL;
  if(l==r)
  {
    S.insert(1LL*(x[r+1]-x[l])*(y[l]-d));
    return 1LL*(x[r+1]-x[l])*(y[l]-d);
  }
  long long ll,rr;
  int mid=where(l,r),cnt;
  ll=dfs(l,mid-1,y[mid]);
  rr=dfs(mid+1,r,y[mid]);
  if(ll<rr)ll^=rr^=ll^=rr;
  S.erase(S.find(ll));
  S.insert(ll+1LL*(x[r+1]-x[l])*(y[mid]-d));
  return ll+1LL*(x[r+1]-x[l])*(y[mid]-d);
}

int main()
{
  long long res=0;
  int i,n,m;
  scanf("%d",&n);
  n>>=1;
  n--;
  init();
  for(i=0;i<=n;i++)
  {
    scanf("%*d%*d%d%d",&x[i],&y[i]);
    update(i,y[i]);
  }
  scanf("%d",&m);
  dfs(0,n-1,0);
  for(it=S.end(),i=0;i<m&&it!=S.begin();i++)
  {
    it--;
    res+=*it;
  }
  printf("%lld",res);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8240 KB Output is correct
2 Correct 0 ms 8240 KB Output is correct
3 Correct 4 ms 8240 KB Output is correct
4 Correct 0 ms 8240 KB Output is correct
5 Correct 0 ms 8240 KB Output is correct
6 Correct 0 ms 8240 KB Output is correct
7 Correct 0 ms 8240 KB Output is correct
8 Correct 0 ms 8240 KB Output is correct
9 Correct 0 ms 8240 KB Output is correct
10 Correct 0 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8240 KB Output is correct
2 Correct 0 ms 8240 KB Output is correct
3 Correct 4 ms 8240 KB Output is correct
4 Correct 0 ms 8240 KB Output is correct
5 Correct 0 ms 8240 KB Output is correct
6 Correct 4 ms 8312 KB Output is correct
7 Correct 0 ms 8240 KB Output is correct
8 Correct 0 ms 8240 KB Output is correct
9 Correct 4 ms 8240 KB Output is correct
10 Correct 0 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 11276 KB Output is correct
2 Correct 136 ms 11276 KB Output is correct
3 Correct 140 ms 12876 KB Output is correct
4 Correct 160 ms 12968 KB Output is correct
5 Correct 160 ms 12968 KB Output is correct
6 Correct 124 ms 19832 KB Output is correct
7 Correct 152 ms 17404 KB Output is correct
8 Correct 152 ms 17408 KB Output is correct
9 Correct 152 ms 10484 KB Output is correct
10 Correct 148 ms 10484 KB Output is correct
11 Correct 116 ms 19832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 11276 KB Output is correct
2 Correct 124 ms 11276 KB Output is correct
3 Correct 148 ms 13096 KB Output is correct
4 Correct 152 ms 12828 KB Output is correct
5 Correct 156 ms 12956 KB Output is correct
6 Correct 120 ms 19832 KB Output is correct
7 Correct 160 ms 17404 KB Output is correct
8 Correct 144 ms 17404 KB Output is correct
9 Correct 156 ms 10484 KB Output is correct
10 Correct 168 ms 10484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 11276 KB Output is correct
2 Correct 140 ms 11276 KB Output is correct
3 Correct 156 ms 13076 KB Output is correct
4 Correct 156 ms 13100 KB Output is correct
5 Correct 152 ms 12956 KB Output is correct
6 Correct 156 ms 17404 KB Output is correct
7 Correct 148 ms 17404 KB Output is correct
8 Correct 156 ms 10484 KB Output is correct
9 Correct 164 ms 10484 KB Output is correct