답안 #621281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
621281 2022-08-03T16:23:43 Z A_D 말 (IOI15_horses) C++14
0 / 100
1500 ms 54048 KB
#include "horses.h"

#include <bits/stdc++.h>

using namespace std;

const int N=1e6+100;
const long long MOD=1e9+7;
const long long L=32;
long long x[N];
long long y[N];
set<int> st;
long long sum=1;
int n;
vector<int> vec;
long long seg[4*N];
long long seg2[4*N];

long long po(long long b,long long p)
{
    if(p==0)return 1;
    if(p==1)return b;
    if(p%2){
        return (b*po(b,p-1))%MOD;
    }
    long long r=po(b,p/2);
    return (r*r)%MOD;
}


long long modinv(int v)
{
    return po(v,MOD-2);
}




void build(int p,int s,int e)
{
    if(s==e){
        seg[p]=y[s];
        seg2[p]=x[s];
        return;
    }
    int mid=(s+e)/2;
    build(p*2,s,mid);
    build(p*2+1,mid+1,e);
    seg[p]=max(seg[p*2],seg[p*2+1]);
    seg2[p]=(seg2[p*2]*seg2[p*2+1])%MOD;
}

void update(int p,int s,int e,int i,int val)
{
    if(s==e){
        seg[p]=val;
        return;
    }
    int mid=(s+e)/2;
    if(i<=mid){
        update(p*2,s,mid,i,val);
    }
    else{
        update(p*2+1,mid+1,e,i,val);
    }
    seg[p]=max(seg[p*2],seg[p*2+1]);
}




void update2(int p,int s,int e,int i,int val)
{
    if(s==e){
        seg2[p]=val;
        return;
    }
    int mid=(s+e)/2;
    if(i<=mid){
        update2(p*2,s,mid,i,val);
    }
    else{
        update2(p*2+1,mid+1,e,i,val);
    }
    seg2[p]=(seg2[p*2]*seg2[p*2+1])%MOD;
}



long long get(int p,int s,int e,int a,int b)
{
    if(a<=s&&e<=b){
        return seg[p];
    }
    if(s>b||e<a)return 0;
    int mid=(s+e)/2;
    return max(get(p*2,s,mid,a,b),get(p*2+1,mid+1,e,a,b));
}
long long get2(int p,int s,int e,int a,int b)
{
    if(b==-1)return 1;
    if(a<=s&&e<=b){
        return seg2[p];
    }
    if(s>b||e<a)return 1;
    int mid=(s+e)/2;
    return (get2(p*2,s,mid,a,b)*get2(p*2+1,mid+1,e,a,b))%MOD;
}
void filvec()
{
    vec.clear();
    int cnt=0;
    for(auto x:st){
        vec.push_back(-x);
        cnt++;
        if(cnt==L)continue;
    }
    reverse(vec.begin(),vec.end());
}
long long getansst()
{
    filvec();
    long long ret=seg[1];
    long long sum=1,sum2=1,val=seg[1];
    if(vec.size()==L)val=0;
    for(auto i:vec){
        sum*=x[i];
        sum%=MOD;
        sum2*=x[i];
        long long u=sum2*get(1,0,n-1,i,n-1);
        if(u>val){
            sum2=1;
            ret=sum*get(1,0,n-1,i,n-1);
            val=y[i];
        }
    }
    ret%=MOD;
    return ret;
}



int init(int N, int X[], int Y[]){
    st.clear();
    n=N;
    for(int i=0;i<N;i++){
        x[i]=X[i];
        y[i]=Y[i];
        if(x[i]!=1){
            st.insert(-i);
        }
    }
    build(1,0,n-1);
    filvec();
    int h=vec[0];
    for(int i=0;i<h;i++){
        sum*=x[i];
        sum%=MOD;
    }

    long long u=getansst();
    u*=get2(1,0,n-1,0,vec[0]-1);
    u%=MOD;
    return (int)u;
}

int updateX(int pos, int val) {

    update2(1,0,n-1,pos,val);

    return (getansst()*get2(1,0,n-1,0,vec[0]-1))%MOD;
}

int updateY(int pos, int val) {

    update(1,0,n-1,pos,val);

    filvec();

    return (getansst()*get2(1,0,n-1,0,vec[0]-1))%MOD;




}

Compilation message

horses.cpp: In function 'void filvec()':
horses.cpp:113:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  113 |     for(auto x:st){
      |              ^
horses.cpp:10:11: note: shadowed declaration is here
   10 | long long x[N];
      |           ^
horses.cpp: In function 'long long int getansst()':
horses.cpp:124:15: warning: declaration of 'sum' shadows a global declaration [-Wshadow]
  124 |     long long sum=1,sum2=1,val=seg[1];
      |               ^~~
horses.cpp:13:11: note: shadowed declaration is here
   13 | long long sum=1;
      |           ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:143:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
  143 | int init(int N, int X[], int Y[]){
      |          ~~~~^
horses.cpp:7:11: note: shadowed declaration is here
    7 | const int N=1e6+100;
      |           ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:171:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  171 |     return (getansst()*get2(1,0,n-1,0,vec[0]-1))%MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:180:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  180 |     return (getansst()*get2(1,0,n-1,0,vec[0]-1))%MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 2 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 2 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1602 ms 54048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 2 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 2 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -