답안 #838353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838353 2023-08-26T16:50:42 Z AbdelmagedNour 말 (IOI15_horses) C++17
100 / 100
521 ms 51208 KB
#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "horses.h"
const int mod=(1e9)+7,MAXN=500005;
int add(int a,int b){
	a+=b;
    if(a>=mod)a-=mod;
    return a;
}
int sub(int a,int b){
    a-=b;
    if(a<0)a+=mod;
    return a;
}
int mul(int a,int b){
	return(a*1LL*b)%mod;
}
int power(int x,int n){
    int res=1;
    while(n){
        if(n&1)res=mul(res,x);
        x=mul(x,x);
        n>>=1;
    }
    return res;
}
int inv(int a){
	return power(a,mod-2);
}
int divide(int a,int b){
	return mul(a,inv(b));
}
int x[MAXN],y[MAXN],n;
set<int>not_one;
int bit[MAXN],tree[1<<20];
void upd(int i,int val){
    for(;i<=n;i+=i&-i)bit[i]=mul(bit[i],val);
}
int qry(int i){
	int res=1;
    for(;i>=1;i-=i&-i)res=mul(res,bit[i]);
	return res;
}
void update(int l,int r,int p,int idx,int val){
    if(l==r){
        tree[p]=val;
        return;
    }
    int md=(l+r)>>1;
    if(md>=idx)update(l,md,p*2+1,idx,val);
    else update(md+1,r,p*2+2,idx,val);
    tree[p]=max(tree[p*2+1],tree[p*2+2]);
}
int query(int l,int r,int p,int l_q,int r_q){
    if(l>r_q||r<l_q)return 0;
    if(l>=l_q&&r<=r_q)return tree[p];
    int md=(l+r)>>1;
    return max(query(l,md,p*2+1,l_q,r_q),query(md+1,r,p*2+2,l_q,r_q));
}
int solve(){
	long long cur_factor=1,all_factor=1;
	int last=n+1;
	long long ans=0,best=0;
	for(auto it=not_one.rbegin();it!=not_one.rend();it++){
		int cur_pos=*it;
	    int cur_y=query(1,n,0,cur_pos,last-1);
		if(cur_y>best*cur_factor) {
			best=cur_y;
			ans=mul(qry(cur_pos),cur_y);
			cur_factor=1;
		}
		cur_factor*=x[cur_pos];
		all_factor*=x[cur_pos];
		if(all_factor>mod)break;
		last=cur_pos;
	}
	return ans;
}
int init(int N, int X[], int Y[]) {
	n=N;
	x[0]=y[0]=1;
	for(int i=1;i<=n;i++)x[i]=X[i-1],y[i]=Y[i-1];
	for(int i=0;i<=n;i++)bit[i]=1;
	for(int i=1;i<=n;i++){
		upd(i,x[i]);
		update(1,n,0,i,y[i]);
	}
	for(int i=1;i<=n;i++){
		if(x[i]>1)not_one.insert(i);
	}
	not_one.insert(1);
	return solve();
}
int updateX(int pos,int val){	
    pos++;
    upd(pos,divide(val,x[pos]));
	if(x[pos]>1&&pos>1)not_one.erase(pos);
    x[pos]=val;
    if(x[pos]>1)not_one.insert(pos);
    return solve();
}

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

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:17:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   17 |  return(a*1LL*b)%mod;
      |        ~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:78:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   78 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 224 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 324 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 38584 KB Output is correct
2 Correct 317 ms 51144 KB Output is correct
3 Correct 308 ms 42376 KB Output is correct
4 Correct 375 ms 46196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 328 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 100 ms 18244 KB Output is correct
34 Correct 91 ms 18264 KB Output is correct
35 Correct 206 ms 48500 KB Output is correct
36 Correct 202 ms 48508 KB Output is correct
37 Correct 128 ms 16412 KB Output is correct
38 Correct 138 ms 29260 KB Output is correct
39 Correct 85 ms 16196 KB Output is correct
40 Correct 190 ms 43756 KB Output is correct
41 Correct 101 ms 16284 KB Output is correct
42 Correct 113 ms 16272 KB Output is correct
43 Correct 183 ms 43976 KB Output is correct
44 Correct 181 ms 43992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 220 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 328 KB Output is correct
33 Correct 521 ms 42344 KB Output is correct
34 Correct 319 ms 51208 KB Output is correct
35 Correct 313 ms 42316 KB Output is correct
36 Correct 366 ms 46204 KB Output is correct
37 Correct 94 ms 18312 KB Output is correct
38 Correct 90 ms 18252 KB Output is correct
39 Correct 209 ms 48516 KB Output is correct
40 Correct 206 ms 48564 KB Output is correct
41 Correct 128 ms 16488 KB Output is correct
42 Correct 138 ms 29220 KB Output is correct
43 Correct 86 ms 16228 KB Output is correct
44 Correct 187 ms 43580 KB Output is correct
45 Correct 106 ms 16264 KB Output is correct
46 Correct 113 ms 16360 KB Output is correct
47 Correct 179 ms 44016 KB Output is correct
48 Correct 184 ms 44008 KB Output is correct
49 Correct 163 ms 21268 KB Output is correct
50 Correct 153 ms 21284 KB Output is correct
51 Correct 307 ms 50468 KB Output is correct
52 Correct 249 ms 49956 KB Output is correct
53 Correct 504 ms 19580 KB Output is correct
54 Correct 263 ms 33168 KB Output is correct
55 Correct 157 ms 17236 KB Output is correct
56 Correct 253 ms 45424 KB Output is correct
57 Correct 318 ms 17948 KB Output is correct
58 Correct 441 ms 18432 KB Output is correct
59 Correct 180 ms 44024 KB Output is correct