QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#488914 | #8819. CNOI Knowledge | Mathew_Miao | RE | 0ms | 0kb | C++23 | 3.0kb | 2024-07-24 16:17:57 | 2024-07-24 16:18:07 |
answer
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e3+10;
const int N=1e3;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,m,cnt=0;
int a[MAXN],s[MAXN];
namespace SA{
int cnt;
int sa[MAXN],h[MAXN];
int rnk[MAXN<<1],lst[MAXN<<1];
int sum[MAXN],id[MAXN];
inline void build(){
cnt=m;
for(int i=1;i<=m;i++)
{
rnk[i]=s[i];
}
#define cnt_sort(sth) {\
memset(sum,0,sizeof(int)*(cnt+1));\
for(int i=1;i<=m;i++)\
{\
sum[rnk[sth]]++;\
}\
for(int i=1;i<=cnt;i++)\
{\
sum[i]+=sum[i-1];\
}\
for(int i=m;i;i--)\
{\
sa[sum[rnk[sth]]]=sth;\
sum[rnk[sth]]--;\
}\
}
cnt_sort(i);
for(int w=1;w<=m;w<<=1)
{
for(int i=1;i<=w;i++)
{
id[i]=m-w+i;
}
int now=w;
for(int i=1;i<=m;i++)
{
if(sa[i]>w){
now++;
id[now]=sa[i]-w;
}
}
cnt_sort(id[i]);
cnt=0;
memcpy(lst,rnk,sizeof(int)*(m+1));
for(int i=1;i<=m;i++)
{
if((lst[sa[i]]^lst[sa[i-1]])||(lst[sa[i]+w]^lst[sa[i-1]+w])){
cnt++;
}
rnk[sa[i]]=cnt;
}
if(cnt==m){
break;
}
}
int k=0;
for(int i=1;i<=m;i++)
{
if(k){
k--;
}
while(s[i+k]==s[sa[rnk[i]-1]+k])
{
k++;
}
h[rnk[i]]=k;
}
}
}
inline int query(int l,int r){
if(!a[r]){
printf("? %d %d\n",l,r);
fflush(stdout);
int res;
scanf("%d",&res);
return res;
}
m=r-l+1;
memcpy(s+1,a+l,sizeof(int)*m);
SA::build();
int res=m*(m+1)>>1;
for(int i=1;i<=m;i++)
{
res-=SA::h[i];
}
return res;
}
signed main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int l=0,r=i-1,mid;
while(l<r)
{
mid=(l+r+1)>>1;
if((query(mid,i)-query(mid,i-1))^(i-mid+1)){
l=mid;
}
else{
r=mid-1;
}
}
if(!l){
cnt++;
a[i]=cnt;
}
else{
a[i]=a[l];
}
}
putchar('!');
putchar(' ');
for(int i=1;i<=n;i++)
{
printf("%d ",a[i]);
}
putchar('\n');
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
12 3 6 6 10 10 15 10 21 15 27 20 14 6 9 20 10
output:
? 1 2 ? 1 3 ? 2 4 ? 1 4 ? 2 5 ? 1 5 ? 3 6 ? 1 6 ? 3 7 ? 1 7 ? 2 7 ? 4 8 ? 6 8 ? 5 8 ? 4 9 ? 6 9