답안 #69040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69040 2018-08-19T14:57:43 Z theknife2001 말 (IOI15_horses) C++17
0 / 100
1500 ms 52688 KB
#include "horses.h"
#include <bits/stdc++.h>
#define mid (l+r)/2

using namespace std;
const int N=5e5+55;
long long tree[N*4][2];
long long x[N];
long long y[N];
set < int > st;
int m=1e9+7;
int n;

void build(int l , int r , int node)
{
    if(l==r)
    {
        tree[node][0]=x[l];
        tree[node][1]=y[l];
        return ;
    }
    build(l,mid,node*2);
    build(mid+1,r,node*2+1);
    tree[node][0]=tree[node*2][0]*tree[node*2+1][0];
    tree[node][0]%=m;
    tree[node][1]=tree[node*2][1]*tree[node*2+1][1];
    tree[node][1]%=m;
}

void update(int l , int r , int node , int ind , int val , int q)
{
    if(l==r&&l==ind)
    {
        tree[node][q]=val;
        return ;
    }
    if(ind<=mid)
        update(l,mid,node*2,ind,val,q);
    else
        update(mid+1,r,node*2+1,ind,val,q);
    tree[node][q]=tree[node*2][q]*tree[node*2+1][q];
    tree[node][q]%=m;
}

long long query(int l , int r , int node , int x , int y , int q)
{
    if(x<=l&&r<=y)
        return tree[node][q];
    if(l>y||r<x)
        return 1;
    return (query(l,mid,node*2,x,y,q)*query(mid+1,r,node*2+1,x,y,q))%m;
}

int solve()
{
	int i=n-1;
    long long ret=0;
	long long temp=1;
	long long s=1;
	set < int > :: iterator it=st.begin();
	for(;it!=st.end();it++)
    {
        i=-(*it);
        s*=x[i];
        if(s>10000000000)
            break;
    }
    it++;
    set < int > :: iterator j=it;
    it--;
    bool q=0;
    int bestpos=n-1;
    for(;it!=st.end();it++)
    {
        i=-(*it);
        temp*=x[i];
        if(y[i]*temp>ret)
        {
            ret=y[i]*temp;
            bestpos=i;
        }
        if(ret<0||y[i]*temp<0)
        {
            q=1;
            break;
        }
    }
    if(q)
    {
        it=j;
        temp=1;
        ret=0;
        bestpos=n-1;
        for(;it!=st.end();it++)
        {
            i=-(*it);
            temp*=x[i];
            if(query(0,n-1,1,i,(-(*upper_bound(st.begin(),st.end(),-i))-1),1)*temp>ret)
            {
                ret=query(0,n-1,1,i,(-(*upper_bound(st.begin(),st.end(),-i))-1),1)*temp;
                bestpos=i;
            }
            if(ret<0||query(0,n-1,1,i,(-(*upper_bound(st.begin(),st.end(),-i))-1),1)*temp<0)
            {
                assert(0);
            }
        }
    }
    return (query(0,n-1,1,bestpos,(-(*upper_bound(st.begin(),st.end(),-bestpos))-1),1)*query(0,n-1,1,0,bestpos,0))%m;
}

int init(int N, int X[], int Y[])
{
	n=N;
	st.insert(0);
    for(int i=0;i<N;i++)
    {
        x[i]=X[i];
        if(x[i]!=1)
            st.insert(-i);
        y[i]=Y[i];
    }
    build(0,n-1,1);
    return solve();
}

int updateX(int pos, int val) {
    if(x[pos]==1)
        st.insert(-pos);
    x[pos]=val;
    if(val==1&&pos)
        st.erase(-pos);
    update(0,n-1,1,pos,val,0);
    return solve();
}

int updateY(int pos, int val)
{
    y[pos]=val;
    update(0,n-1,1,pos,val,1);
    return solve();
}

Compilation message

horses.cpp: In function 'long long int query(int, int, int, int, int, int)':
horses.cpp:45:65: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 long long query(int l , int r , int node , int x , int y , int q)
                                                                 ^
horses.cpp:9:11: note: shadowed declaration is here
 long long y[N];
           ^
horses.cpp:45:65: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 long long query(int l , int r , int node , int x , int y , int q)
                                                                 ^
horses.cpp:8:11: note: shadowed declaration is here
 long long x[N];
           ^
horses.cpp: In function 'int solve()':
horses.cpp:109:115: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (query(0,n-1,1,bestpos,(-(*upper_bound(st.begin(),st.end(),-bestpos))-1),1)*query(0,n-1,1,0,bestpos,0))%m;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:112:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[])
                                 ^
horses.cpp:6:11: note: shadowed declaration is here
 const int N=5e5+55;
           ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1559 ms 52688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 52688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 52688 KB Output isn't correct
2 Halted 0 ms 0 KB -