답안 #1090574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090574 2024-09-18T13:05:26 Z owoovo 말 (IOI15_horses) C++17
34 / 100
95 ms 49492 KB
#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
#define ld float
#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]=log2f(x[i]);
		y2[i]=log2f(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,log2f(val)-log2f(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,log2f(val)-log2f(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, float)':
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:138:18: warning: conversion from 'long long int' to 'float' may change value [-Wconversion]
  138 |   x2[i]=log2f(x[i]);
      |               ~~~^
horses.cpp:139:18: warning: conversion from 'long long int' to 'float' may change value [-Wconversion]
  139 |   y2[i]=log2f(y[i]);
      |               ~~~^
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:31: warning: conversion from 'int' to 'float' may change value [-Wconversion]
  153 |  seg.modify(1,n,pos,n,0,log2f(val)-log2f(x[pos]));
      |                               ^~~
horses.cpp:153:47: warning: conversion from 'long long int' to 'float' may change value [-Wconversion]
  153 |  seg.modify(1,n,pos,n,0,log2f(val)-log2f(x[pos]));
      |                                          ~~~~~^
horses.cpp:153:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  153 |  seg.modify(1,n,pos,n,0,log2f(val)-log2f(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,log2f(val)-log2f(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:33: warning: conversion from 'int' to 'float' may change value [-Wconversion]
  161 |  seg.modify(1,n,pos,pos,0,log2f(val)-log2f(y[pos]));
      |                                 ^~~
horses.cpp:161:49: warning: conversion from 'long long int' to 'float' may change value [-Wconversion]
  161 |  seg.modify(1,n,pos,pos,0,log2f(val)-log2f(y[pos]));
      |                                            ~~~~~^
horses.cpp:161:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  161 |  seg.modify(1,n,pos,pos,0,log2f(val)-log2f(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 9 ms 23900 KB Output is correct
2 Correct 9 ms 23920 KB Output is correct
3 Correct 10 ms 23904 KB Output is correct
4 Correct 10 ms 23928 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23936 KB Output is correct
7 Correct 8 ms 23936 KB Output is correct
8 Correct 9 ms 23896 KB Output is correct
9 Correct 10 ms 24152 KB Output is correct
10 Correct 10 ms 23900 KB Output is correct
11 Correct 9 ms 23900 KB Output is correct
12 Correct 10 ms 23824 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 10 ms 23900 KB Output is correct
15 Correct 9 ms 23908 KB Output is correct
16 Correct 9 ms 23904 KB Output is correct
17 Correct 9 ms 23904 KB Output is correct
18 Correct 10 ms 23904 KB Output is correct
19 Correct 9 ms 23972 KB Output is correct
20 Correct 10 ms 23904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24160 KB Output is correct
2 Correct 10 ms 23904 KB Output is correct
3 Correct 9 ms 23932 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 10 ms 23904 KB Output is correct
6 Correct 9 ms 23904 KB Output is correct
7 Correct 10 ms 23776 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23912 KB Output is correct
10 Correct 9 ms 23816 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 8 ms 23720 KB Output is correct
13 Correct 10 ms 23900 KB Output is correct
14 Correct 9 ms 23736 KB Output is correct
15 Correct 10 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 9 ms 23836 KB Output is correct
18 Correct 9 ms 23900 KB Output is correct
19 Correct 9 ms 23900 KB Output is correct
20 Correct 9 ms 23900 KB Output is correct
21 Correct 10 ms 23900 KB Output is correct
22 Correct 11 ms 23792 KB Output is correct
23 Correct 10 ms 23900 KB Output is correct
24 Correct 10 ms 23900 KB Output is correct
25 Correct 11 ms 23936 KB Output is correct
26 Correct 12 ms 23940 KB Output is correct
27 Correct 10 ms 23896 KB Output is correct
28 Correct 10 ms 23796 KB Output is correct
29 Correct 10 ms 23896 KB Output is correct
30 Correct 9 ms 23940 KB Output is correct
31 Correct 9 ms 23900 KB Output is correct
32 Correct 13 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 49492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 23900 KB Output is correct
2 Correct 9 ms 23932 KB Output is correct
3 Correct 11 ms 23896 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 10 ms 23864 KB Output is correct
6 Correct 11 ms 23896 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23932 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23896 KB Output is correct
11 Correct 12 ms 23900 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23856 KB Output is correct
15 Correct 9 ms 23940 KB Output is correct
16 Correct 10 ms 23948 KB Output is correct
17 Correct 10 ms 23896 KB Output is correct
18 Correct 9 ms 23976 KB Output is correct
19 Correct 9 ms 23900 KB Output is correct
20 Correct 10 ms 23760 KB Output is correct
21 Correct 10 ms 23900 KB Output is correct
22 Correct 10 ms 23808 KB Output is correct
23 Correct 10 ms 23900 KB Output is correct
24 Correct 9 ms 23900 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23900 KB Output is correct
27 Correct 10 ms 23988 KB Output is correct
28 Correct 10 ms 23896 KB Output is correct
29 Correct 10 ms 23900 KB Output is correct
30 Correct 10 ms 23900 KB Output is correct
31 Correct 15 ms 24156 KB Output is correct
32 Correct 10 ms 23896 KB Output is correct
33 Incorrect 64 ms 48644 KB Output isn't correct
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 9 ms 23928 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23756 KB Output is correct
7 Correct 10 ms 23944 KB Output is correct
8 Correct 9 ms 23896 KB Output is correct
9 Correct 9 ms 23900 KB Output is correct
10 Correct 9 ms 23964 KB Output is correct
11 Correct 9 ms 23900 KB Output is correct
12 Correct 11 ms 23932 KB Output is correct
13 Correct 9 ms 23800 KB Output is correct
14 Correct 9 ms 23908 KB Output is correct
15 Correct 9 ms 23896 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 12 ms 24188 KB Output is correct
18 Correct 8 ms 23896 KB Output is correct
19 Correct 9 ms 23928 KB Output is correct
20 Correct 8 ms 23900 KB Output is correct
21 Correct 8 ms 23952 KB Output is correct
22 Correct 9 ms 23900 KB Output is correct
23 Correct 10 ms 23900 KB Output is correct
24 Correct 9 ms 23900 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23924 KB Output is correct
27 Correct 10 ms 23900 KB Output is correct
28 Correct 9 ms 23856 KB Output is correct
29 Correct 9 ms 23892 KB Output is correct
30 Correct 9 ms 24040 KB Output is correct
31 Correct 8 ms 23900 KB Output is correct
32 Correct 9 ms 23828 KB Output is correct
33 Incorrect 95 ms 49456 KB Output isn't correct
34 Halted 0 ms 0 KB -