답안 #70166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70166 2018-08-22T12:12:24 Z khohko popa (BOI18_popa) C++17
0 / 100
11 ms 512 KB
#include <bits/stdc++.h>
#ifndef KHOKHO
#include "popa.h"
#endif // KHOKHO
#pragma GCC optimize("O3")
using namespace std;
#define ll int
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(1e12+100))
#define MX ((ll)(1e6+100))
#define ARRS ((ll)(2e6+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;

#ifdef KHOKHO
	ll aa[ARRS];
	ll qr=0;
	int query(int a, int b, int c, int d){
		ll x=0,y=0;
		qr++;
		for(int i=a; i<=b; i++)x=__gcd(x,aa[i]);
		for(int i=c; i<=d; i++)y=__gcd(y,aa[i]);
		return x==y;
	}
#endif
ll l[ARRS];
ll r[ARRS];
ll f[ARRS];
ll pr[ARRS];

ll dp[1100][1100];
bitset<1100> ps[1100];
bitset<1100> psl[1100];
bitset<1100> tb;

ll bld(ll l,ll r,int *lt,int *rt){
	//slv(l,r);
	ll x=dp[l][r]-1;
	if(x==-2)return -1;
	if(x==-1)return -1;
	//cout<<l<<" "<<r<<" "<<x<<endl;
	lt[x]=bld(l,x,lt,rt);
	rt[x]=bld(x+1,r,lt,rt);
	return x;
}


int solve(int n, int* lt, int* rt){
	stack<ll> sk;
	for(int i=0; i<n; i++)lt[i]=rt[i]=-1;
	ll rut=-1;
	for(int i=0; i<n; i++){
		l[i]=i;
		while(l[i]&&query(l[l[i]-1],i,i,i))
			l[i]=l[l[i]-1];
		//cout<<qr<<endl;
		if(rut==-1||l[i]<=rut){
			lt[i]=rut;
			pr[rut]=i;
			rut=i;
		}
		else if(l[i]==i){
			rt[i-1]=i;
			pr[i]=i-1;
		}
		else {
			ll x=l[i];
			while(f[x])x++;
			ll p=pr[x];
			rt[p]=i;
			lt[i]=x;
			f[x]=1;
		}
	}
	return rut;
}

#ifdef KHOKHO
int pa[ARRS];
int pb[ARRS];

int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w",stdout);
	#endif // KHOKHO
	//ios::sync_with_stdio(0);

	ll n;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>aa[i];
	}
	ll rt=solve(n,pa,pb);
	cout<<rt<<endl;
	for(int i=0; i<n; i++){
		cout<<pa[i]<<" ";
	}
	cout<<endl;
	for(int i=0; i<n; i++){
		cout<<pb[i]<<" ";
	}
	cout<<endl;
	cout<<endl;
	cout<<"asked:"<<qr<<endl;

}
#endif
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 328 KB not a valid binary tree
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 512 KB not a valid binary tree
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 512 KB not a valid binary tree
2 Halted 0 ms 0 KB -