QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648319#7434. 冷たい部屋、一人lichenghanWA 0ms30284kbC++143.1kb2024-10-17 18:23:582024-10-17 18:23:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 18:23:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:30284kb
  • [2024-10-17 18:23:58]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
#ifndef LCH
#define USE_FREAD_FWRITE
#endif
#define READ_NEGATIVE
#define WRITE_NEGATIVE
namespace IO{
#ifdef USE_FREAD_FWRITE
#define SIZE (1<<20)
	char in[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;
	char getchar(){ return p1==p2&&(p2=(p1=in)+fread(in,1,SIZE,stdin),p1==p2)?EOF:*p1++; }
	void flush(){ int len=p3-out; fwrite(p3=out,1,len,stdout); }
	void putchar(char ch){ if(p3==out+SIZE)flush(); *p3++=(ch); }
	struct Flush{~Flush(){flush();}}_;
#else
	char getchar(){ return ::getchar(); }
	void putchar(char ch){ ::putchar(ch); }
	void flush(){}
#endif
	template<typename type=int> inline type read(){
#ifdef READ_NEGATIVE
		type x(0);bool flag(0);char ch=getchar();
		for(;ch<'0'||ch>'9';ch=getchar())flag^=ch=='-';
		for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
		return flag?-x:x;
#else
		type x(0);char ch=getchar();
		for(;ch<'0'||ch>'9';ch=getchar());
		for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
		return x;
#endif
	}
	template<typename type>
	inline void write(type x){
#ifdef WRITE_NEGATIVE
		if(x<0)x=-x,putchar('-');
#endif
		static int Stack[50],top(0);
		do Stack[++top]=x%10,x/=10;while(x);
		while(top) putchar(Stack[top--]|48);
	}
}
using IO::read;
using IO::write;
const int N=2e5+10;
// const int B=505;
const int B=N;
struct BIT{
	int s0[N],s1[N>>7],s2[N>>14];
	void c(int x){
		// printf("c %d\n",x);
		s0[x]++;
		s1[x>>7]++;
		s2[x>>14]++;
	}
	int q(int x){
		int ans=0;
		for(int i=1;i<(x>>14);i++) ans+=s2[i];
		for(int i=x>>14<<7;i<(x>>7);i++) ans+=s1[i];
		for(int i=x>>7<<7;i<=x;i++) ans+=s0[i];
		// printf("q %d -> %d\n",x,ans);
		return ans;
	}
}Tpre;
template<class comp> struct sparse_table{
	static comp _c;
	int st[21][N];
	void init(int n,int* a){
		for(int i=1;i<=n;i++) st[0][i]=a[i];
		for(int j=1;j<=20;j++){
			auto F=st[j],G=st[j-1];
			for(int i=1;i<=n-(1<<j)+1;i++){
				F[i]=min(G[i],G[i+(1<<j>>1)],_c);
			}
		}
	}
	int q(int l,int r){
		int len=__lg(r-l+1);
		return min(st[len][l],st[len][r-(1<<len)+1],_c);
	}
};
sparse_table<less<int>> Tmin;
sparse_table<greater<int>> Tmax;
int n,m;
int a[N],b[N];
vector<int> ra[N];
int rnk[N];
int rb[N];
int ql[N],qr[N];
vector<int> rql[N];
ll ans[N];
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++) a[i]=read(),ra[a[i]].push_back(i);
	for(int i=1;i<=n;i++) for(int j=0;j<ra[i].size();j++) rnk[ra[i][j]]=j;
	for(int i=1;i<=n;i++) b[i]=read(),rb[b[i]]=i;
	Tmin.init(n,b); Tmax.init(n,b);
	for(int i=1;i<=m;i++){
		ql[i]=read(); qr[i]=read();
		rql[ql[i]].push_back(i);
	}
	for(int i=n;i>=1;i--) {
		int u=rb[i];
		int cs=ra[a[u]].size();
		vector<int>& V=ra[a[u]];
		if(cs<=B){
			int rk=rnk[u];
			for(int j=rk+1;j<cs;j++){
				int mi=Tmin.q(u,V[j]),ma=Tmax.q(u,V[j]);
				if(mi!=b[u]) break;
				Tpre.c(ma);
			}
			for(int j=rk-1;j>=0;j--){
				int mi=Tmin.q(V[j],u),ma=Tmax.q(V[j],u);
				if(mi!=b[u]) break;
				Tpre.c(ma);
			}
		}
		for(int id:rql[i]){
			ans[id]+=Tpre.q(qr[id]);
		}
	}
	for(int i=1;i<=m;i++){
		write(ans[i]);
		IO::putchar('\n');
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 30284kb

input:

100 100
4 1 5 1 2 1 7 5 3 7 2 3 6 6 5 3 2 2 4 1 6 5 6 2 2 2 7 6 1 3 6 3 5 6 7 6 1 2 3 3 4 2 1 1 5 4 4 3 6 7 1 1 6 1 5 6 2 3 7 4 2 4 6 7 7 3 5 3 7 2 3 3 5 1 4 7 1 2 2 5 2 2 4 3 4 7 2 7 7 3 7 3 6 6 5 4 5 4 7 6
93 52 12 70 25 36 18 37 27 99 68 40 84 3 76 57 60 19 33 41 92 87 58 13 15 43 28 63 64 59 31 ...

output:

1
0
8
25
1
1
2
6
0
0
2
1
3
11
7
5
23
12
1
0
0
2
2
10
0
0
6
2
0
0
3
1
31
0
11
1
1
14
9
17
1
0
1
6
5
0
7
3
0
1
0
1
1
5
0
13
10
10
2
1
0
0
5
4
0
0
2
5
4
1
2
2
0
1
6
1
0
1
0
8
0
0
4
1
15
1
10
2
1
14
11
1
2
0
0
9
0
1
1
10

result:

wrong answer 3rd numbers differ - expected: '13', found: '8'