QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648361 | #7434. 冷たい部屋、一人 | lichenghan | RE | 0ms | 0kb | C++14 | 883b | 2024-10-17 18:37:13 | 2024-10-17 18:37:13 |
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
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];
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
while(m--){
int l,r;
cin>>l>>r;
int ans=0;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i]==a[j]&&Tmin.q(i,j)>=l&&Tmax.q(i,j)<=r) ans++;
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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 ...