답안 #880469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880469 2023-11-29T13:10:07 Z josanneo22 Fish (IOI08_fish) C++17
100 / 100
599 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;
 namespace fast {
#pragma GCC optimize(Ofast)
#pragma GCC optimization (unroll-loops)
#pragma GCC target(avx,avx2,fma)
#pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native)
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
}
using namespace fast;

inline string read_string() {
    char ch = getchar(); string st1 = "";
    while (!((ch >= 'A') && (ch <= 'Z'))) ch = getchar();
    while ((ch >= 'A') && (ch <= 'Z'))  st1 += ch, ch = getchar();
    return st1;
}
char buf[1 << 23], * p1 = buf, * p2 = buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename T> inline void re(T& x) { x = 0; T f = 1; char ch = getchar();  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * (1 << 1) + x * (1 << 3) + (ch - 48); ch = getchar(); } x *= f; }
template<typename x, typename... y>void re(x& a, y&... b) { re(a); re(b...); }
template<typename T> inline void ps(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9)  ps(x / 10); putchar(x % 10 + '0'); }
template<typename x, typename... y>void ps(x& a, y&... b) { ps(a); putchar(' '); ps(b...); }
#define sp putchar(' ')
#define nl putchar('\n')

#define ls p<<1
#define rs p<<1|1
const int N=5e5+500;
int t[N<<2],F,K,M,cnt[N],f[N];
set<int> S[N];
void modify(int p,int l,int r,int x,int v){
	if(l==r){
		t[p]=v%M;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid) modify(ls,l,mid,x,v);
	if(x>=mid+1) modify(rs,mid+1,r,x,v);
	t[p]=((t[ls]%M)*(t[rs]%M))%M;
	return;
}
int query(int p,int l,int r,int ql,int qr){
	if(ql<=l && r<=qr) return t[p];
	int mid=(l+r)>>1,ans=1;
	if(ql<=mid) ans*=query(ls,l,mid,ql,qr);
	ans%=M;
	if(qr>=mid+1) ans*=query(rs,mid+1,r,ql,qr);
	return ans%M;
}
struct fish{
	int len,gem;
	bool operator <(const fish &b){ return len<b.len;}
}a[N];
 
int main(){
	re(F,K,M);
	for(int i=1;i<=F;i++)
		re(a[i].len,a[i].gem);
	sort(a+1,a+1+F);
	int T=K;
	for(int i=F;i>=1;i--){
		if(!cnt[a[i].gem])
			cnt[a[i].gem]=T--;
		a[i].gem=cnt[a[i].gem];
	}
	for(int i=1;i<=F;i++) cnt[i]=0;
	for(int i=1;i<=F;i++){
		cnt[a[i].gem]++;
		S[a[i].gem].insert(i);
	}
	for(int i=1;i<=K;i++) cnt[i]++;
	for(int i=1;i<=K;i++) modify(1,1,K,i,cnt[i]);
	int ans=0;
	for(int i=F,j=F;i>=1;i--){
		if(*prev(S[a[i].gem].end())==i){
			while(j>=1 && a[j].len*2>a[i].len){
				int gem=a[j].gem;
				--cnt[gem]; modify(1,1,K,gem,cnt[gem]);
				j--;
			}
			int gem=a[i].gem;
			f[gem]=j;
			int x=*S[gem].upper_bound(f[gem]),l=gem,r=K,res=K;
			while(l<=r){
				int mid=(l+r)>>1;
				if(f[mid]<x) res=mid,l=mid+1;
				else r=mid-1;
			}
			int before=(gem==1?1:query(1,1,K,1,gem-1));
			int after=(gem==res?1:query(1,1,K,gem+1,res))+(cnt[gem]-1);
			before%=M; after%=M; 
			ans+=before*after; ans%=M;
		}
	}
	ps(ans);
}

Compilation message

fish.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization (unroll-loops)
      | 
fish.cpp:4:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
    4 | #pragma GCC optimize(Ofast)
      |                      ^~~~~
fish.cpp:6:20: warning: '#pragma GCC option' is not a string [-Wpragmas]
    6 | #pragma GCC target(avx,avx2,fma)
      |                    ^~~
fish.cpp:7:20: warning: '#pragma GCC option' is not a string [-Wpragmas]
    7 | #pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native)
      |                    ^~~
fish.cpp:27:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   27 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
fish.cpp:34:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   34 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
fish.cpp:36:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   36 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
fish.cpp:50:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   50 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
fish.cpp:56:27: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   56 | inline string read_string() {
      |                           ^
fish.cpp:56:27: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:56:27: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:56:27: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:64:41: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   64 | template<typename T> inline void re(T& x) { x = 0; T f = 1; char ch = getchar();  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * (1 << 1) + x * (1 << 3) + (ch - 48); ch = getchar(); } x *= f; }
      |                                         ^
fish.cpp:64:41: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:64:41: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:64:41: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:65:57: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   65 | template<typename x, typename... y>void re(x& a, y&... b) { re(a); re(b...); }
      |                                                         ^
fish.cpp:65:57: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:65:57: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:65:57: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:66:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   66 | template<typename T> inline void ps(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9)  ps(x / 10); putchar(x % 10 + '0'); }
      |                                        ^
fish.cpp:66:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:66:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:66:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:67:57: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   67 | template<typename x, typename... y>void ps(x& a, y&... b) { ps(a); putchar(' '); ps(b...); }
      |                                                         ^
fish.cpp:67:57: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:67:57: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:67:57: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:76:42: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   76 | void modify(int p,int l,int r,int x,int v){
      |                                          ^
fish.cpp:76:42: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:76:42: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:76:42: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:87:42: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   87 | int query(int p,int l,int r,int ql,int qr){
      |                                          ^
fish.cpp:87:42: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:87:42: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:87:42: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:97:31: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   97 |  bool operator <(const fish &b){ return len<b.len;}
      |                               ^
fish.cpp:97:31: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:97:31: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:97:31: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
fish.cpp:100:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  100 | int main(){
      |          ^
fish.cpp:100:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
fish.cpp:100:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
fish.cpp:100:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31064 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31068 KB Output is correct
2 Correct 189 ms 60500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 45468 KB Output is correct
2 Correct 90 ms 48212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31324 KB Output is correct
2 Correct 8 ms 31832 KB Output is correct
3 Correct 8 ms 31476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 50592 KB Output is correct
2 Correct 230 ms 61084 KB Output is correct
3 Correct 210 ms 61040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 60500 KB Output is correct
2 Correct 270 ms 61268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 50848 KB Output is correct
2 Correct 246 ms 61296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 58148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 60304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 55832 KB Output is correct
2 Correct 400 ms 61992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 406 ms 59988 KB Output is correct
2 Correct 289 ms 52688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 376 ms 60232 KB Output is correct
2 Correct 410 ms 62060 KB Output is correct
3 Correct 368 ms 63056 KB Output is correct
4 Correct 412 ms 65104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 62356 KB Output is correct
2 Correct 564 ms 65500 KB Output is correct
3 Correct 533 ms 65536 KB Output is correct
4 Correct 599 ms 65352 KB Output is correct