답안 #1090575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090575 2024-09-18T13:06:09 Z owoovo 말 (IOI15_horses) C++17
100 / 100
485 ms 146988 KB
#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first 
#define S second
#define lc id*2+1
#define rc id*2+2
using namespace std;
const ll p=1e9+7;
ll pw(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)ans*=a,ans%=p;
		b>>=1,a*=a,a%=p;
	}
	return ans;
}
ll x[500010],y[500010],n;
ld x2[500010],y2[500010],u[500010];
struct BIT{
	ll ori[500010];
	void init(){
		for(int i=0;i<=n;i++)ori[i]=1;
		return;
	}
	void modify(ll x,int pos){
		while(pos<=n){
			ori[pos]*=x;
			ori[pos]%=p;
			pos+=pos&(-pos);
		}
		return;
	}
	ll query(ll pos){
		ll ans=1;
		while(pos){
			ans*=ori[pos];
			ans%=p;
			pos-=pos&(-pos);
		}
		return ans;
	}
}bit;
struct node{
	pair<ld,int> val;
	ld tag;
	node(){
	}
};
struct SEG_TREE{
	node ori[2000010];
	void pull(int l,int r,int id){
		if(l==r)return;
		ori[id].val=max(ori[lc].val,ori[rc].val);
		return;
	}
	void push(int l,int r,int id){
		ori[id].val.F+=ori[id].tag;
		if(l!=r){
			int m=(l+r)>>1;
			ori[lc].tag+=ori[id].tag;
			ori[rc].tag+=ori[id].tag;
		}
		ori[id].tag=0;
		return;
	}
	void build(int l,int r,int id){
		ori[id].tag=0;
		if(l==r){
			ori[id].val={u[l],l};
			return;
		}
		int m=(l+r)>>1;
		build(l,m,lc);
		build(m+1,r,rc);
		pull(l,r,id);
		return;
	}
	void modify(int l,int r,int ml,int mr,int id,ld x){
		push(l,r,id);
		if(l==ml&&r==mr){
			ori[id].tag+=x;
			push(l,r,id);
			return;
		}
		int m=(l+r)>>1;
        push(l,m,lc);
        push(m+1,r,rc);
        pull(l,r,id);
		if(mr<=m){
			modify(l,m,ml,mr,lc,x);
		}else if(m<ml){
			modify(m+1,r,ml,mr,rc,x);
		}else{
			modify(l,m,ml,m,lc,x);
			modify(m+1,r,m+1,mr,rc,x);
		}
        push(l,m,lc);
        push(m+1,r,rc);
        pull(l,r,id);
		return;
	}
	pair<ld,int> query(int l,int r,int ql,int qr,int id){
		push(l,r,id);
		if(l==ql&&r==qr){
			return ori[id].val;
		}
		int m=(l+r)>>1;
		if(qr<=m){
			return query(l,m,ql,qr,lc);
		}else if(m<ql){
			return query(m+1,r,ql,qr,rc);
		}else{
			return max(query(l,m,ql,m,lc),query(m+1,r,m+1,qr,rc));
		}
	}
}seg;
 
ll q(){
	pair<ld,int> ans=seg.query(1,n,1,n,0);
	ll a=bit.query(ans.S);
	a*=y[ans.S];
	a%=p;
	return a;
}
 
 
 
int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=0;i<n;i++){
		x[i+1]=X[i];
		y[i+1]=Y[i];
	}
	bit.init();
	for(int i=1;i<=n;i++){
		x2[i]=log2l(x[i]);
		y2[i]=log2l(y[i]);
		bit.modify(x[i],i);
	}
	ld now=0;
	for(int i=1;i<=n;i++){	
		now+=x2[i];
		u[i]=now+y2[i];
	}
	seg.build(1,n,0);
	return q();
}
 
int updateX(int pos, int val) {	
	pos+=1;
	seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
	bit.modify((pw(x[pos],p-2)*val)%p,pos);
	x[pos]=val;
	return q();
}
 
int updateY(int pos, int val) {
	pos+=1;
	seg.modify(1,n,pos,pos,0,log2l(val)-log2l(y[pos]));
	y[pos]=val;
	return q();
}

Compilation message

horses.cpp: In member function 'void BIT::modify(long long int, int)':
horses.cpp:27:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   27 |  void modify(ll x,int pos){
      |                 ^
horses.cpp:19:4: note: shadowed declaration is here
   19 | ll x[500010],y[500010],n;
      |    ^
horses.cpp: In member function 'void SEG_TREE::push(int, int, int)':
horses.cpp:61:8: warning: unused variable 'm' [-Wunused-variable]
   61 |    int m=(l+r)>>1;
      |        ^
horses.cpp: In member function 'void SEG_TREE::modify(int, int, int, int, int, long double)':
horses.cpp:80:50: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   80 |  void modify(int l,int r,int ml,int mr,int id,ld x){
      |                                                  ^
horses.cpp:19:4: note: shadowed declaration is here
   19 | ll x[500010],y[500010],n;
      |    ^
horses.cpp: In function 'long long int q()':
horses.cpp:121:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |  pair<ld,int> ans=seg.query(1,n,1,n,0);
      |                               ^
horses.cpp:121:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |  pair<ld,int> ans=seg.query(1,n,1,n,0);
      |                                   ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:147:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  147 |  seg.build(1,n,0);
      |              ^
horses.cpp:148:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  148 |  return q();
      |         ~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:153:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  153 |  seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
      |               ^
horses.cpp:153:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  153 |  seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
      |                     ^
horses.cpp:156:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  156 |  return q();
      |         ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:161:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  161 |  seg.modify(1,n,pos,pos,0,log2l(val)-log2l(y[pos]));
      |               ^
horses.cpp:163:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  163 |  return q();
      |         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 94396 KB Output is correct
2 Correct 44 ms 94196 KB Output is correct
3 Correct 48 ms 94292 KB Output is correct
4 Correct 47 ms 94236 KB Output is correct
5 Correct 48 ms 94288 KB Output is correct
6 Correct 45 ms 94300 KB Output is correct
7 Correct 44 ms 94296 KB Output is correct
8 Correct 48 ms 94272 KB Output is correct
9 Correct 53 ms 94292 KB Output is correct
10 Correct 47 ms 94240 KB Output is correct
11 Correct 49 ms 94288 KB Output is correct
12 Correct 45 ms 94296 KB Output is correct
13 Correct 45 ms 94292 KB Output is correct
14 Correct 47 ms 94224 KB Output is correct
15 Correct 47 ms 94292 KB Output is correct
16 Correct 49 ms 94164 KB Output is correct
17 Correct 47 ms 94296 KB Output is correct
18 Correct 47 ms 94332 KB Output is correct
19 Correct 46 ms 94288 KB Output is correct
20 Correct 47 ms 94160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 94292 KB Output is correct
2 Correct 42 ms 94376 KB Output is correct
3 Correct 43 ms 94248 KB Output is correct
4 Correct 42 ms 94288 KB Output is correct
5 Correct 45 ms 94292 KB Output is correct
6 Correct 42 ms 94292 KB Output is correct
7 Correct 44 ms 94292 KB Output is correct
8 Correct 42 ms 94380 KB Output is correct
9 Correct 43 ms 94288 KB Output is correct
10 Correct 43 ms 94292 KB Output is correct
11 Correct 42 ms 94288 KB Output is correct
12 Correct 42 ms 94340 KB Output is correct
13 Correct 47 ms 94288 KB Output is correct
14 Correct 42 ms 94292 KB Output is correct
15 Correct 43 ms 94288 KB Output is correct
16 Correct 44 ms 94288 KB Output is correct
17 Correct 44 ms 94296 KB Output is correct
18 Correct 45 ms 94292 KB Output is correct
19 Correct 46 ms 94288 KB Output is correct
20 Correct 46 ms 94292 KB Output is correct
21 Correct 47 ms 94180 KB Output is correct
22 Correct 44 ms 94256 KB Output is correct
23 Correct 49 ms 94288 KB Output is correct
24 Correct 49 ms 94292 KB Output is correct
25 Correct 48 ms 94288 KB Output is correct
26 Correct 49 ms 94304 KB Output is correct
27 Correct 50 ms 94460 KB Output is correct
28 Correct 50 ms 94312 KB Output is correct
29 Correct 49 ms 94288 KB Output is correct
30 Correct 51 ms 94288 KB Output is correct
31 Correct 48 ms 94384 KB Output is correct
32 Correct 49 ms 94308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 134256 KB Output is correct
2 Correct 417 ms 146840 KB Output is correct
3 Correct 439 ms 138080 KB Output is correct
4 Correct 468 ms 141980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 94288 KB Output is correct
2 Correct 47 ms 94308 KB Output is correct
3 Correct 46 ms 94236 KB Output is correct
4 Correct 48 ms 94292 KB Output is correct
5 Correct 46 ms 94288 KB Output is correct
6 Correct 46 ms 94288 KB Output is correct
7 Correct 46 ms 94292 KB Output is correct
8 Correct 48 ms 94288 KB Output is correct
9 Correct 47 ms 94288 KB Output is correct
10 Correct 52 ms 94292 KB Output is correct
11 Correct 48 ms 94288 KB Output is correct
12 Correct 47 ms 94288 KB Output is correct
13 Correct 46 ms 94272 KB Output is correct
14 Correct 44 ms 94300 KB Output is correct
15 Correct 44 ms 94300 KB Output is correct
16 Correct 47 ms 94324 KB Output is correct
17 Correct 48 ms 94288 KB Output is correct
18 Correct 47 ms 94288 KB Output is correct
19 Correct 48 ms 94180 KB Output is correct
20 Correct 47 ms 94340 KB Output is correct
21 Correct 49 ms 94288 KB Output is correct
22 Correct 48 ms 94292 KB Output is correct
23 Correct 47 ms 94292 KB Output is correct
24 Correct 52 ms 94388 KB Output is correct
25 Correct 50 ms 94288 KB Output is correct
26 Correct 47 ms 94288 KB Output is correct
27 Correct 48 ms 94292 KB Output is correct
28 Correct 47 ms 94292 KB Output is correct
29 Correct 47 ms 94288 KB Output is correct
30 Correct 48 ms 94292 KB Output is correct
31 Correct 48 ms 94292 KB Output is correct
32 Correct 49 ms 94292 KB Output is correct
33 Correct 185 ms 133456 KB Output is correct
34 Correct 181 ms 137296 KB Output is correct
35 Correct 193 ms 144396 KB Output is correct
36 Correct 188 ms 144208 KB Output is correct
37 Correct 171 ms 135764 KB Output is correct
38 Correct 176 ms 136520 KB Output is correct
39 Correct 159 ms 135540 KB Output is correct
40 Correct 180 ms 139348 KB Output is correct
41 Correct 159 ms 135508 KB Output is correct
42 Correct 159 ms 135504 KB Output is correct
43 Correct 157 ms 139892 KB Output is correct
44 Correct 164 ms 139816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 94288 KB Output is correct
2 Correct 47 ms 94288 KB Output is correct
3 Correct 46 ms 94204 KB Output is correct
4 Correct 45 ms 94364 KB Output is correct
5 Correct 52 ms 94224 KB Output is correct
6 Correct 51 ms 94192 KB Output is correct
7 Correct 44 ms 94292 KB Output is correct
8 Correct 46 ms 94292 KB Output is correct
9 Correct 45 ms 94292 KB Output is correct
10 Correct 46 ms 94176 KB Output is correct
11 Correct 45 ms 94288 KB Output is correct
12 Correct 51 ms 94296 KB Output is correct
13 Correct 49 ms 94300 KB Output is correct
14 Correct 44 ms 94224 KB Output is correct
15 Correct 46 ms 94292 KB Output is correct
16 Correct 48 ms 94268 KB Output is correct
17 Correct 50 ms 94292 KB Output is correct
18 Correct 46 ms 94288 KB Output is correct
19 Correct 45 ms 94288 KB Output is correct
20 Correct 47 ms 94288 KB Output is correct
21 Correct 44 ms 94292 KB Output is correct
22 Correct 49 ms 94268 KB Output is correct
23 Correct 48 ms 94284 KB Output is correct
24 Correct 47 ms 94304 KB Output is correct
25 Correct 57 ms 94548 KB Output is correct
26 Correct 49 ms 94288 KB Output is correct
27 Correct 50 ms 94384 KB Output is correct
28 Correct 48 ms 94468 KB Output is correct
29 Correct 48 ms 94288 KB Output is correct
30 Correct 50 ms 94288 KB Output is correct
31 Correct 47 ms 94292 KB Output is correct
32 Correct 47 ms 94288 KB Output is correct
33 Correct 327 ms 134484 KB Output is correct
34 Correct 456 ms 146988 KB Output is correct
35 Correct 446 ms 138320 KB Output is correct
36 Correct 485 ms 142064 KB Output is correct
37 Correct 194 ms 137552 KB Output is correct
38 Correct 167 ms 137424 KB Output is correct
39 Correct 171 ms 144356 KB Output is correct
40 Correct 168 ms 144340 KB Output is correct
41 Correct 154 ms 135508 KB Output is correct
42 Correct 153 ms 136384 KB Output is correct
43 Correct 148 ms 135544 KB Output is correct
44 Correct 163 ms 139344 KB Output is correct
45 Correct 144 ms 135460 KB Output is correct
46 Correct 145 ms 135504 KB Output is correct
47 Correct 173 ms 139860 KB Output is correct
48 Correct 162 ms 139892 KB Output is correct
49 Correct 447 ms 139324 KB Output is correct
50 Correct 456 ms 139384 KB Output is correct
51 Correct 394 ms 146260 KB Output is correct
52 Correct 379 ms 145732 KB Output is correct
53 Correct 449 ms 137812 KB Output is correct
54 Correct 398 ms 138416 KB Output is correct
55 Correct 331 ms 136532 KB Output is correct
56 Correct 403 ms 141132 KB Output is correct
57 Correct 343 ms 137048 KB Output is correct
58 Correct 347 ms 137652 KB Output is correct
59 Correct 160 ms 139856 KB Output is correct