Submission #28055

# Submission time Handle Problem Language Result Execution time Memory
28055 2017-07-15T06:34:06 Z top34051 Horses (IOI15_horses) C++14
0 / 100
933 ms 72360 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
#define pdl pair<double,long long>
#define mod 1000000007LL

int n;
int a[maxn];
int b[maxn];
pdl tree[maxn*4];
pdl lazy[maxn*4];

pdl fus(pdl x,pdl y) {
    return {x.first+y.first,(x.second*y.second)%mod};
}

long long inv(long long x,long long y){
    long long quo,temp;
    long long oldr = x, r = y;
    long long olds = 1, s = 0;
    long long oldt = 0, t = 1;
    while(r)
    {
        quo = oldr/r;
        temp = oldr;
        oldr = r;
        r = temp-quo*r;
        temp = olds;
        olds = s;
        s = temp-quo*s;
        temp = oldt;
        oldt = t;
        t = temp-quo*t;
    }
    return (olds+mod)%mod;
}

void upd(int now) {
    tree[now] = fus(tree[now],lazy[now]);
    lazy[now<<1] = fus(lazy[now<<1],lazy[now]);
    lazy[now<<1|1] = fus(lazy[now<<1|1],lazy[now]);
    lazy[now] = {0,1};
}

void update(int now,int l,int r,int x,int y,double val1,long long val2) {
    upd(now);
    if(l>r || l>y || r<x) return ;
    if(x<=l && r<=y) {
        lazy[now] = {val1,val2};
        upd(now);
        return ;
    }
    int mid = (l+r)/2;
    update(now<<1,l,mid,x,y,val1,val2); update(now<<1|1,mid+1,r,x,y,val1,val2);
    tree[now] = max(tree[now<<1],tree[now<<1|1]);
}

void build(int now,int l,int r) {
    if(l==r) {
        tree[now] = lazy[now] = {0,1LL};
        return ;
    }
    int mid = (l+r)/2;
    build(now<<1,l,mid); build(now<<1|1,mid+1,r);
    tree[now] = lazy[now] = {0,1};

}

int init(int N, int X[], int Y[]) {
    n = N;
    for(int i=0;i<n;i++) a[i] = X[i], b[i] = Y[i];
    build(1,0,n-1);
    for(int i=0;i<n;i++) update(1,0,n-1,i,n-1,(double)log2(a[i]),a[i]);
    for(int i=0;i<n;i++) update(1,0,n-1,i,i,(double)log2(b[i]),b[i]);
    printf("%lld\n",tree[1].second);
	return 0;
}

int updateX(int pos, int val) {
    update(1,0,n-1,pos,n-1,-(double)log2(a[pos]),inv(a[pos],mod));
    a[pos] = val;
	update(1,0,n-1,pos,n-1,(double)log2(a[pos]),a[pos]);
    printf("%lld\n",tree[1].second);
	return 0;
}

int updateY(int pos, int val) {
    update(1,0,n-1,pos,pos,-(double)log2(b[pos]),inv(b[pos],mod));
    b[pos] = val;
	update(1,0,n-1,pos,pos,(double)log2(b[pos]),b[pos]);
    printf("%lld\n",tree[1].second);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 68448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 68448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 933 ms 72360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 68448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 68448 KB Output isn't correct
2 Halted 0 ms 0 KB -