Killer Problem(暴力)
题意:
给定一个序列,每次询问l到r之间两个数差的绝对值的最小值。
分析:
开始以为是线段树离线处理,实际暴力就好!
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; typedef pair<int,int> PII; typedef long long ll; #define lson l,m,rt<<1 #define pi acos(-1.0) #define rson m+1,r,rt<<11 #define All 1,N,1 #define read freopen("in.txt", "r", stdin) const ll INFll = 0x3f3f3f3f3f3f3f3fLL; const int INF= 0x7ffffff; const int mod = 1000000007; const int maxn=10000; int num[10010],n,a[200010],q; int solve(int l,int r){ if(r-l+1>maxn) return 0; memset(num,0,sizeof(num)); for(int i=l;i<=r;++i) { if(!num[a[i]]) num[a[i]]=1; else return 0; } int minv=maxn,tmp=-maxn; for(int i=1;i<=maxn;++i){ if(num[i]) { minv=min(minv,i-tmp); tmp=i; } } return minv; } int main() { int t; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d",&a[i]); scanf("%d",&q); int l,r; while(q--){ scanf("%d%d",&l,&r); l--;r--; printf("%d\n",solve(l,r)); } } return 0; }