답안 #1098299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098299 2024-10-09T08:43:40 Z alexander707070 말 (IOI15_horses) C++14
100 / 100
860 ms 49488 KB
#include<bits/stdc++.h>
#include "horses.h"

#define MAXN 500007
using namespace std;

const long long mod=1e9+7;

struct ST{
    int tree[4*MAXN];
    long long mult[4*MAXN];

    void update(int v,int l,int r,int pos,int val){
        if(l==r){
            tree[v]=val;
            mult[v]=val;
        }else{
            int tt=(l+r)/2;
            if(pos<=tt)update(2*v,l,tt,pos,val);
            else update(2*v+1,tt+1,r,pos,val);

            tree[v]=max(tree[2*v],tree[2*v+1]);
            mult[v]=(mult[2*v]*mult[2*v+1])%mod;
        }
    }

    int getmax(int v,int l,int r,int ll,int rr){
        if(ll>rr)return 0;
        if(l==ll and r==rr){
            return tree[v];
        }else{
            int tt=(l+r)/2;
            return max( getmax(2*v,l,tt,ll,min(tt,rr)) , getmax(2*v+1,tt+1,r,max(tt+1,ll),rr) );
        }
    }

    int solve(int v,int l,int r){
        if(l==r)return l;
        int tt=(l+r)/2;

        if(tree[2*v+1]>1)return solve(2*v+1,tt+1,r);
        return solve(2*v,l,tt);
    }

    int findpos(int v,int l,int r,int ll,int rr){
        if(ll>rr)return 0;
        if(l==ll and r==rr){
            if(tree[v]>1)return solve(v,l,r);
            return 0;
        }else{
            int tt=(l+r)/2;

            int curr=findpos(2*v+1,tt+1,r,max(tt+1,ll),rr);
            if(curr!=0)return curr;

            return findpos(2*v,l,tt,ll,min(tt,rr));
        }
    }

    long long getmult(int v,int l,int r,int ll,int rr){
        if(ll>rr)return 1;
        if(l==ll and r==rr)return mult[v];

        int tt=(l+r)/2;
        return (getmult(2*v,l,tt,ll,min(tt,rr)) * getmult(2*v+1,tt+1,r,max(tt+1,ll),rr))%mod;
    }
}xs,ys;

int n;
long long x[MAXN],y[MAXN];

int calc(){
    
    long long mult=1,res=0,ans=0;
    int to=n+1;

    vector< pair<int,int> > w;

    while(to>1 and mult<mod){
        int s=xs.findpos(1,1,n,1,to-1);
        if(s==0){
            w.push_back({1,to-1}); break;
        }else{
            w.push_back({s,to-1}); to=s;
            mult*=x[s];
        }
    }

    mult=1;
    for(int i=w.size()-1;i>=0;i--){
        long long curr=(long long) mult*ys.getmax(1,1,n,w[i].first,w[i].second);

        if(curr>res){
            res=curr;
            ans=((res%mod)*xs.getmult(1,1,n,1,w.back().first))%mod;
        }

        if(i>0)mult*=x[w[i-1].first];
    }

    return ans;
}

int init(int N, int X[], int Y[]) {
//int init(int N, vector<int> X, vector<int> Y) {

	n=N;
    for(int i=1;i<=n;i++){
        x[i]=X[i-1]; y[i]=Y[i-1];

        xs.update(1,1,n,i,x[i]);
        ys.update(1,1,n,i,y[i]);
    }

    return calc();
}

int updateX(int pos, int val) {	
	x[pos+1]=val;
    xs.update(1,1,n,pos+1,val);

    return calc();
}

int updateY(int pos, int val) {
	y[pos+1]=val;
    ys.update(1,1,n,pos+1,val);

    return calc();
}

/*int main(){

    init(3,{2,1,3},{3,4,1});
    cout<<updateY(1,2)<<"\n";

    return 0;
}*/

Compilation message

horses.cpp: In function 'int calc()':
horses.cpp:90:23: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   90 |     for(int i=w.size()-1;i>=0;i--){
      |               ~~~~~~~~^~
horses.cpp:101:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |     return ans;
      |            ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:111:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |         xs.update(1,1,n,i,x[i]);
      |                           ~~~^
horses.cpp:112:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |         ys.update(1,1,n,i,y[i]);
      |                           ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 37716 KB Output is correct
2 Correct 260 ms 37572 KB Output is correct
3 Correct 282 ms 37584 KB Output is correct
4 Correct 324 ms 37712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 556 KB Output is correct
33 Correct 174 ms 36916 KB Output is correct
34 Correct 164 ms 36728 KB Output is correct
35 Correct 185 ms 36828 KB Output is correct
36 Correct 183 ms 36692 KB Output is correct
37 Correct 233 ms 36692 KB Output is correct
38 Correct 174 ms 36688 KB Output is correct
39 Correct 158 ms 36692 KB Output is correct
40 Correct 179 ms 42832 KB Output is correct
41 Correct 177 ms 38856 KB Output is correct
42 Correct 193 ms 38928 KB Output is correct
43 Correct 164 ms 43020 KB Output is correct
44 Correct 165 ms 42996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 486 ms 37804 KB Output is correct
34 Correct 253 ms 37716 KB Output is correct
35 Correct 288 ms 37712 KB Output is correct
36 Correct 336 ms 37716 KB Output is correct
37 Correct 167 ms 36692 KB Output is correct
38 Correct 166 ms 36692 KB Output is correct
39 Correct 180 ms 36688 KB Output is correct
40 Correct 175 ms 36696 KB Output is correct
41 Correct 231 ms 36692 KB Output is correct
42 Correct 178 ms 36688 KB Output is correct
43 Correct 155 ms 36844 KB Output is correct
44 Correct 175 ms 42672 KB Output is correct
45 Correct 169 ms 38736 KB Output is correct
46 Correct 181 ms 38992 KB Output is correct
47 Correct 165 ms 43196 KB Output is correct
48 Correct 160 ms 42968 KB Output is correct
49 Correct 278 ms 42828 KB Output is correct
50 Correct 260 ms 42836 KB Output is correct
51 Correct 293 ms 49488 KB Output is correct
52 Correct 254 ms 48976 KB Output is correct
53 Correct 860 ms 41040 KB Output is correct
54 Correct 375 ms 41552 KB Output is correct
55 Correct 240 ms 39820 KB Output is correct
56 Correct 234 ms 44436 KB Output is correct
57 Correct 395 ms 40596 KB Output is correct
58 Correct 569 ms 41020 KB Output is correct
59 Correct 169 ms 43152 KB Output is correct