Language: Java

#include<iostream>
#include<algorithm>
#include<cstring>
 
using namespace std;
const int N=100010;
int a[N],b[N],rt[N*20],ls[N*20],rs[N*20],sum[N*20],vis[N*20];
 
int id;
void build(int &o,int l,int r)
{
	o=++id;
	sum[o]=0;
	if(l==r) return;
	int m=(l+r)>>1;
	build(ls[o],l,m);
	build(rs[o],m+1,r);
}
 
void update(int &o,int l,int r,int last,int pos,int val)
{
	o=++id;
	ls[o]=ls[last];
	rs[o]=rs[last];
	sum[o]=sum[last]+val;
	if(l==r) return;
	int m=(l+r)>>1;
	if(pos<=m)
	  update(ls[o],l,m,ls[last],pos,val);
	else
	  update(rs[o],m+1,r,rs[last],pos,val);
}
//查询区间[L,R]内小于等于k的个数 
int query(int pos,int root,int l,int r)
{
	if(l==r)
	  return sum[root];
	int m=(l+r)>>1;
	if(m>=pos)
	  return sum[rs[root]]+query(pos,ls[root],l,m);
	else
	  return query(pos,rs[root],m+1,r);
}
 
int main()
{
	int T,n,q,l,r,k;
 	memset(vis,0,sizeof(vis));
  	scanf("%d%d",&n,&q);
 	 for(int i=1;i<=n;i++)
   	 scanf("%d",&a[i]);
 	 	id=0;
  	build(rt[0],1,n);
 	 for(int i=1;i<=n;i++){
    if(!vis[a[i]])//如果a[i]还未出现过 
      update(rt[i],1,n,rt[i-1],i,1);
    else{//如果a[i]已经出现了 
      int pos=vis[a[i]];
      int temp;
      update(temp,1,n,rt[i-1],pos,-1);
      update(rt[i],1,n,temp,i,1);
    }
    vis[a[i]]=i;
  }
  while(q--){
    scanf("%d%d",&l,&r);
    int num=query(l,rt[r],1,n);
    printf("%d\n",num);
  }
	return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include<iostream>
^
Main.java:2: error: illegal character: '#'
#include<algorithm>
^
Main.java:3: error: illegal character: '#'
#include<cstring>
^
Main.java:6: error: class, interface, enum, or record expected
const int N=100010;
^
Main.java:7: error: class, interface, enum, or record expected
int a[N],b[N],rt[N*20],ls[N*20],rs[N*20],sum[N*20],vis[N*20];
^
Main.java:9: error: unnamed classes are a preview feature and are disabled by default.
int id;
^
  (use --enable-preview to enable unnamed classes)
Main.java:10: error: <identifier> expected
void build(int &o,int l,int r)
              ^
Main.java:10: error: class, interface, enum, or record expected
void build(int &o,int l,int r)
                  ^
Main.java:13: error: class, interface, enum, or record expected
	sum[o]=0;
	^
Main.java:14: error: class, interface, enum, or record expected
	if(l==r) return;
	^
Main.java:16: error: class, interface, enum, or record expected
	build(ls[o],l,m);
	^
Main.java:17: error: class, interface, enum, or record expected
	build(rs[o],m+1,r);
	^
Main.java:18: error: class, interface, enum, or record expected
}
^
Main.java:23: error: class, interface, enum, or record expected
	ls[o]=ls[last];
	^
Main.java:24: error: class, interface, enum, or record expected
	rs[o]=rs[last];
	^
Main.java:25: error: class, interface, enum, or record expected
	sum[o]=sum[last]+val;
	^
Main.java:26: error: class, interface, enum, or record expected
	if(l==r) return;
	^
Main.java:28: error: class, interface, enum, or record expected
	if(pos<=m)
	^
Main.java:30: error: class, interface, enum, or record expected
	else
	^
Main.java:32: error: class, interface, enum, or record expected
}
^
Main.java:39: error: class, interface, enum, or record expected
	if(m>=pos)
	^
Main.java:41: error: class, interface, enum, or record expected
	else
	^
Main.java:43: error: class, interface, enum, or record expected
}
^
Main.java:48: error: class, interface, enum, or record expected
 	memset(vis,0,sizeof(vis));
 	^
Main.java:49: error: class, interface, enum, or record expected
  	scanf("%d%d",&n,&q);
  	^
Main.java:50: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++)
 	 ^
Main.java:50: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++)
 	             ^
Main.java:50: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++)
 	                  ^
Main.java:52: error: class, interface, enum, or record expected
 	 	id=0;
 	 	^
Main.java:53: error: class, interface, enum, or record expected
  	build(rt[0],1,n);
  	^
Main.java:54: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++){
 	 ^
Main.java:54: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++){
 	             ^
Main.java:54: error: class, interface, enum, or record expected
 	 for(int i=1;i<=n;i++){
 	                  ^
Main.java:57: error: class, interface, enum, or record expected
    else{//??a[i]????? 
    ^
Main.java:60: error: class, interface, enum, or record expected
      update(temp,1,n,rt[i-1],pos,-1);
      ^
Main.java:61: error: class, interface, enum, or record expected
      update(rt[i],1,n,temp,i,1);
      ^
Main.java:62: error: class, interface, enum, or record expected
    }
    ^
Main.java:64: error: class, interface, enum, or record expected
  }
  ^
Main.java:68: error: class, interface, enum, or record expected
    printf("%d\n",num);
    ^
Main.java:69: error: class, interface, enum, or record expected
  }
  ^
Main.java:71: error: class, interface, enum, or record expected
}
^
41 errors