标签:一个 bre logs over out memory integer cto cin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2512 Accepted Submission(s): 1045
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<vector> 5 #include<algorithm> 6 #include<fstream> 7 using namespace std; 8 int a[500005]; 9 long long l[90], r[90]; 10 int main() 11 { 12 int T,n,k; 13 //ifstream cin("ylq.txt"); 14 cin>>T; 15 while(T--) 16 { 17 scanf("%d %d", &n, &k); 18 //cin>>n>>k; 19 for(int i=1;i<=n;i++) scanf("%d", &a[i]); 20 int t; 21 long long ans=0; 22 for(int i=1;i<=n;i++){ 23 t=0; 24 l[t++]=i; 25 int j; 26 for(j=i-1;j>0&&t<k;j--){ 27 if(a[j]>a[i]){ 28 l[t++]=j; 29 } 30 } 31 long long sum=0; 32 if(t==k) 33 { 34 int tmp=1; 35 for(;j>0;j--){ 36 if(a[j]<a[i]) tmp++; 37 else break; 38 } 39 sum+=tmp; 40 for(j=i+1;j<=n&&t>=0;j++){ 41 if(a[j]<a[i]) sum+=tmp; 42 else{ 43 t--; 44 if(t==0) break; 45 tmp=l[t-1]-l[t]; 46 sum+=tmp; 47 } 48 } 49 } 50 else 51 { 52 for(j=i+1;j<=n&&t<k;j++){ 53 if(a[j]>a[i]) l[t++]=j; 54 } 55 if(t==k) 56 { 57 sort(l, l+t); 58 int tmp=l[0]; 59 int p=0; 60 sum+=tmp; 61 for(;j<=n&&p<t;j++){ 62 if(a[j]<a[i]) sum+=tmp; 63 else{ 64 p++; 65 if(l[p]>i) break; 66 tmp=abs(l[p]-l[p-1]); 67 sum+=tmp; 68 } 69 70 } 71 } 72 } 73 ans+=(long long)(sum*a[i]); 74 } 75 cout<<ans<<endl; 76 } 77 }
HDU 6058 Kanade's sum —— 2017 Multi-University Training 3
标签:一个 bre logs over out memory integer cto cin
原文地址:http://www.cnblogs.com/MasterSpark/p/7291129.html