Submission #1085334

# Submission time Handle Problem Language Result Execution time Memory
1085334 2024-09-08T03:59:31 Z guagua0407 Horses (IOI15_horses) C++17
100 / 100
609 ms 80472 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n;
vector<ll> x,y;
const ll inf=1e9;
const ll mod=1e9+7;
vector<ll> segtree,segtreemx;
set<int> S;

void update(int pos,int val,int l=0,int r=n-1,int v=1){
    if(l==r){
        segtree[v]=val;
        return;
    }
    int mid=(l+r)/2;
    if(pos<=mid) update(pos,val,l,mid,v*2);
    else update(pos,val,mid+1,r,v*2+1);
    segtree[v]=segtree[v*2]*segtree[v*2+1]%mod;
}

ll query(int tl,int tr,int l=0,int r=n-1,int v=1){
    if(r<tl or tr<l){
        return 1;
    }
    if(tl<=l and r<=tr){
        return segtree[v];
    }
    int mid=(l+r)/2;
    return query(tl,min(mid,tr),l,mid,v*2)*query(max(mid+1,tl),tr,mid+1,r,v*2+1)%mod;
}

void updatemx(int pos,int val,int l=0,int r=n-1,int v=1){
    if(l==r){
        segtreemx[v]=val;
        return;
    }
    int mid=(l+r)/2;
    if(pos<=mid) updatemx(pos,val,l,mid,v*2);
    else updatemx(pos,val,mid+1,r,v*2+1);
    segtreemx[v]=max(segtreemx[v*2],segtreemx[v*2+1]);
}

ll querymx(int tl,int tr,int l=0,int r=n-1,int v=1){
    if(r<tl or tr<l){
        return 0;
    }
    if(tl<=l and r<=tr){
        return segtreemx[v];
    }
    int mid=(l+r)/2;
    return max(querymx(tl,min(mid,tr),l,mid,v*2),querymx(max(mid+1,tl),tr,mid+1,r,v*2+1));
}

ll go(){
    ll cur=0;
    int prv=n;
    ll ans=1;
    int best=-1;
    for(auto it=S.rbegin();it!=S.rend();it++){
        int pos=*it;
        ll mx=querymx(max(pos,0),prv-1);
        //return mx;
        if(mx>cur){
            cur=mx;
            ans=query(0,pos)*mx%mod;
            best=pos;
            //if(pos==0) return query(0,pos);
        }
        if(pos!=-1){
            if(cur*x[pos]>inf) break;
            cur*=x[pos];
        }
        prv=pos;
    }
	return ans;
}

int init(int N, int X[], int Y[]) {
    n=N;
    x.resize(n);
    y.resize(n);
    segtree=vector<ll>(4*n,1);
    segtreemx=vector<ll>(4*n,1);
    S.insert(-1);
    for(int i=0;i<n;i++){
        x[i]=X[i];
        y[i]=Y[i];
        update(i,x[i]);
        updatemx(i,y[i]);
        if(x[i]>1) S.insert(i);
    }
    return go();
}

int updateX(int pos, int val) {
    if(x[pos]>1) S.erase(pos);
    x[pos]=val;
    if(x[pos]>1) S.insert(pos);
    update(pos,x[pos]);
    return go();
}

int updateY(int pos, int val) {
    y[pos]=val;
    updatemx(pos,y[pos]);
    return go();
}

Compilation message

horses.cpp: In function 'long long int go()':
horses.cpp:66:9: warning: variable 'best' set but not used [-Wunused-but-set-variable]
   66 |     int best=-1;
      |         ^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:96:22: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   96 |         update(i,x[i]);
      |                      ^
horses.cpp:97:24: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   97 |         updatemx(i,y[i]);
      |                        ^
horses.cpp:100:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  100 |     return go();
      |            ~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:107:22: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  107 |     update(pos,x[pos]);
      |                      ^
horses.cpp:108:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |     return go();
      |            ~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:113:24: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  113 |     updatemx(pos,y[pos]);
      |                        ^
horses.cpp:114:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  114 |     return go();
      |            ~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 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 1 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 604 KB Output is correct
# Verdict Execution time Memory 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 604 KB Output is correct
7 Correct 1 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 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 436 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 444 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
# Verdict Execution time Memory Grader output
1 Correct 560 ms 71736 KB Output is correct
2 Correct 396 ms 80468 KB Output is correct
3 Correct 383 ms 71508 KB Output is correct
4 Correct 388 ms 75604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 0 ms 436 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 344 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 432 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 540 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 170 ms 47564 KB Output is correct
34 Correct 169 ms 47440 KB Output is correct
35 Correct 297 ms 77828 KB Output is correct
36 Correct 287 ms 77652 KB Output is correct
37 Correct 205 ms 45648 KB Output is correct
38 Correct 217 ms 58468 KB Output is correct
39 Correct 163 ms 45400 KB Output is correct
40 Correct 275 ms 72788 KB Output is correct
41 Correct 181 ms 45392 KB Output is correct
42 Correct 195 ms 45652 KB Output is correct
43 Correct 259 ms 73296 KB Output is correct
44 Correct 268 ms 73296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 436 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 344 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 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 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 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 2 ms 540 KB Output is correct
33 Correct 577 ms 71528 KB Output is correct
34 Correct 393 ms 80472 KB Output is correct
35 Correct 393 ms 71508 KB Output is correct
36 Correct 389 ms 75600 KB Output is correct
37 Correct 177 ms 47540 KB Output is correct
38 Correct 169 ms 47440 KB Output is correct
39 Correct 304 ms 77908 KB Output is correct
40 Correct 282 ms 77844 KB Output is correct
41 Correct 206 ms 45652 KB Output is correct
42 Correct 220 ms 58348 KB Output is correct
43 Correct 161 ms 45324 KB Output is correct
44 Correct 281 ms 72872 KB Output is correct
45 Correct 174 ms 45528 KB Output is correct
46 Correct 191 ms 45652 KB Output is correct
47 Correct 274 ms 73300 KB Output is correct
48 Correct 262 ms 73136 KB Output is correct
49 Correct 254 ms 50516 KB Output is correct
50 Correct 216 ms 50516 KB Output is correct
51 Correct 403 ms 79620 KB Output is correct
52 Correct 322 ms 79164 KB Output is correct
53 Correct 609 ms 48688 KB Output is correct
54 Correct 337 ms 62288 KB Output is correct
55 Correct 250 ms 46424 KB Output is correct
56 Correct 342 ms 74552 KB Output is correct
57 Correct 392 ms 47188 KB Output is correct
58 Correct 515 ms 47564 KB Output is correct
59 Correct 271 ms 73300 KB Output is correct