# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
309840 | cheetose | 마상시합 토너먼트 (IOI12_tournament) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
int a[100000];
int parent[100000];
Pi query[100000];
int find(int a)
{
if (parent[a] < 0)return a;
return parent[a] = find(parent[a]);
}
void merge(int a, int b)
{
a = find(a), b = find(b);
if (a != b)
{
parent[b] = a;
}
}
int tree[262144];
void init(int node, int S, int E)
{
if (S == E)
{
tree[node] = 1;
return;
}
init(2 * node, S, (S + E) / 2);
init(2 * node + 1, (S + E) / 2 + 1, E);
tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
void upd(int node, int S, int E, int k)
{
tree[node]--;
if (S == E)return;
if (k <= (S + E) / 2)upd(node * 2, S, (S + E) / 2, k);
else upd(node * 2 + 1, (S + E) / 2 + 1, E, k);
}
int findK(int node, int S, int E, int k)
{
if (S == E)return S;
if (k <= tree[node * 2])return findK(node * 2, S, (S + E) / 2, k);
return findK(node * 2 + 1, (S + E) / 2 + 1, E, k - tree[node * 2]);
}
int T[100005];
int n,c,r;
void upd(int i, int k)
{
i++;
while (i <= n+1)
{
T[i] += k;
i += (i&-i);
}
}
int sum(int i)
{
i++;
int c = 0;
while (i > 0)
{
c += T[i];
i -= (i&-i);
}
return c;
}
int lg[100001],mx[100000][17];
int mm(int l,int r){
int tt=lg[r-l+1];
return max(mx[l][tt],mx[r-(1<<tt)+1][tt]);
}
int GetBestPosition(int N, int C, int R, Vi K, Vi S, Vi E){
MEM_1(parent);
fup(i,0,16,1)lg[1<<i]=i;
fup(i,1,100000,1)if(!lg[i])lg[i]=lg[i-1];
n=N,c=C,r=R;
fup(i,0,n-2,1){
a[i]=K[i];
mx[i][0]=a[i];
}
fup(i,0,c-1,1){
int x=S[i],y=E[i];
x++,y++;
int l=findK(1,0,n-1,x),r=findK(1,0,n-1,y);
query[i]=mp(find(l),r);
while(find(l)!=find(r)){
r=find(r);
merge(r-1,r);
upd(1,0,n-1,r-1);
}
}
fup(i,0,c-1,1){
auto [l,r]=query[i];
int t=mm(l,r-1);
if(r>t){
upd(l,1);
upd(r+1,-1);
}
}
int c=-1,w=-1;
fup(i,0,n-1,1){
int t=sum(i);
if(t>c){
c=t;
w=i;
}
}
return w;
}
/*
int main() {
MEM_1(parent);
fup(i,0,16,1)lg[1<<i]=i;
fup(i,1,100000,1)if(!lg[i])lg[i]=lg[i-1];
scanf("%d%d%d",&n,&c,&r);
fup(i,0,n-2,1){
scanf("%d",a+i);
mx[i][0]=a[i];
}
fup(j,0,15,1){
fup(i,0,n-2,1){
if(i+(1<<(j+1))>=n)break;
mx[i][j+1]=max(mx[i][j],mx[i+(1<<j)][j]);
}
}
init(1,0,n-1);
fup(i,0,c-1,1){
int x,y;
scanf("%d%d",&x,&y);
x++,y++;
int l=findK(1,0,n-1,x),r=findK(1,0,n-1,y);
query[i]=mp(find(l),r);
while(find(l)!=find(r)){
r=find(r);
merge(r-1,r);
upd(1,0,n-1,r-1);
}
}
fup(i,0,c-1,1){
auto [l,r]=query[i];
int t=mm(l,r-1);
if(r>t){
upd(l,1);
upd(r+1,-1);
}
}
int c=-1,w=-1;
fup(i,0,n-1,1){
int t=sum(i);
if(t>c){
c=t;
w=i;
}
}
printf("%d\n",w);
}*/