Submission #13357

# Submission time Handle Problem Language Result Execution time Memory
13357 2015-02-13T13:34:46 Z gs14004 수족관 2 (KOI13_aqua2) C++14
100 / 100
365 ms 31460 KB
#include <cstdio>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;

int x[150005], y[150005], hole[150005], n;
map<pi,int> mp;

int h;
long long res;

struct rmq{
    pi tree[530000];
    int lim;
    void init(int n, int *a){
        for(lim = 1; lim <= n; lim <<= 1);
        for(int i=0; i<n; i++){
            tree[i+lim] = pi(a[i],i);
        }
        for(int i=lim-1; i; i--){
            tree[i] = min(tree[2*i],tree[2*i+1]);
        }
    }
    int q(int s, int e){
        s += lim;
        e += lim;
        pi t(1e9,1e9);
        while(s < e){
            if(s%2 == 1) t = min(t,tree[s++]);
            if(e%2 == 0) t = min(t,tree[e--]);
            s >>= 1;
            e >>= 1;
        }
        if(s == e) t = min(t,tree[s]);
        return t.second;
    }
}rmq;

struct bit{
    int tree[265000], lim;
    void init(int n) {
        for(lim = 1; lim <= n+1; lim <<= 1);
    }
    void add(int x, int v){
        x++;
        while(x <= lim){
            tree[x] += v;
            x += x & -x;
        }
    }
    int sum(int x){
        x++;
        int r = 0;
        while(x){
            r += tree[x];
            x -= x & -x;
        }
        return r;
    }
}bit;

double f(int s, int e){
    if(s >= e) return 0;
    int pos = rmq.q(s,e-1);
    int ph = h;
    h = y[pos];
    double r = max(f(s,pos),f(pos+1,e));
    if(bit.sum(e-1) == bit.sum(s-1)){
        res += 1ll * (x[e] - x[s]) * (y[pos] - ph);
    }
    else{
        r += 1.0 * (x[e] - x[s]) * (y[pos] - ph) / (bit.sum(e-1) - bit.sum(s-1));
    }
    h = ph;
    return r;
}

int main(){
    scanf("%d",&n);
    n/=2;
    for (int i=0; i<n; i++) {
        scanf("%*d %*d %d %d",&x[i],&y[i]);
        mp[pi(x[i],y[i])] = i;
    }
    bit.init(n);
    rmq.init(n,y);
    int t;
    scanf("%d",&t);
    for (int i=0; i<t; i++) {
        int s,e;
        scanf("%d %d %*d %*d",&s,&e);
        hole[mp[pi(s,e)]] = 1;
        bit.add(mp[pi(s,e)],1);
    }
    printf("%.2lf\n",f(0,n-1));
    printf("%lld",res);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8152 KB Output is correct
2 Correct 1 ms 8152 KB Output is correct
3 Correct 0 ms 8152 KB Output is correct
4 Correct 0 ms 8152 KB Output is correct
5 Correct 0 ms 8152 KB Output is correct
6 Correct 0 ms 8152 KB Output is correct
7 Correct 0 ms 8152 KB Output is correct
8 Correct 0 ms 8152 KB Output is correct
9 Correct 0 ms 8152 KB Output is correct
10 Correct 0 ms 8152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8152 KB Output is correct
2 Correct 0 ms 8152 KB Output is correct
3 Correct 0 ms 8152 KB Output is correct
4 Correct 0 ms 8152 KB Output is correct
5 Correct 0 ms 8152 KB Output is correct
6 Correct 0 ms 8152 KB Output is correct
7 Correct 0 ms 8152 KB Output is correct
8 Correct 0 ms 8152 KB Output is correct
9 Correct 0 ms 8152 KB Output is correct
10 Correct 2 ms 8152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8152 KB Output is correct
2 Correct 4 ms 8152 KB Output is correct
3 Correct 5 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 6 ms 8396 KB Output is correct
7 Correct 0 ms 8284 KB Output is correct
8 Correct 5 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 16336 KB Output is correct
2 Correct 209 ms 16336 KB Output is correct
3 Correct 365 ms 20212 KB Output is correct
4 Correct 260 ms 20204 KB Output is correct
5 Correct 310 ms 20212 KB Output is correct
6 Correct 188 ms 31460 KB Output is correct
7 Correct 331 ms 24432 KB Output is correct
8 Correct 185 ms 24432 KB Output is correct
9 Correct 306 ms 17524 KB Output is correct
10 Correct 257 ms 17524 KB Output is correct