Farming Mars
预处理优化
AC_Code
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <set> 10 #include <map> 11 #include <sstream> 12 #include <algorithm> 13 using namespace std; 14 typedef long long ll; 15 const int maxn=1e4+9; 16 const ll mod=(ll)(1e9+7); 17 18 int a[maxn],vis[14000006]; 19 bool dp[maxn][maxn]; 20 21 int main() 22 { 23 int i,j,m,n,l,r; 24 double num; 25 scanf("%d %d",&n,&m); 26 for( i=1;i<=n;i++){ 27 scanf("%lf",&num); 28 a[i]=int(num*1000000);///化double为int 29 } 30 for( i=1;i<=n;i++){ 31 int mx=0; 32 for(int j=i;j<=n;j++){ 33 int minn=(j-i+1)/2+1; 34 vis[a[j]]++; 35 mx = max(mx,vis[a[j]]); 36 dp[i][j]=mx>=minn?1:0; 37 } 38 for(j=i;j<=n;j++){ 39 vis[a[j]]=0; 40 } 41 } 42 while( m-- ){ 43 scanf("%d %d",&l,&r); 44 if( dp[l][r]){ 45 printf("usable\n"); 46 } 47 else printf("unusable\n"); 48 } 49 }