Permalink
Browse files

ACEveryDay

  • Loading branch information...
xdlove
xdlove committed May 27, 2016
1 parent 0d7568c commit e3ec23a7c3e90cbbee4559ccf884d37a87bb5fca
Showing with 48 additions and 0 deletions.
  1. +48 −0 ACEveryDay/2016-05-27.cpp
  2. 0 ACEveryDay/README.md
View
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <string.h>
const int N = 8800;
int num[N],cnt[N << 1];
void solve()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0; i < n; ++i)
{
scanf("%d",&num[i]);
}
for(int i = 0; i < n; ++i)
{
if(i) putchar(' ');
memset(cnt,0,sizeof cnt);
int temp = 0,ans = 0;
cnt[0] = 1;
for(int j = i + 1; j < n; ++j)
{
if(num[j] > num[i]) temp++;
else temp--;
if(temp >= 0) cnt[temp]++;
else cnt[-temp + n]++;
}
ans += cnt[0];
temp = 0;
for(int j = i - 1; j >= 0; --j)
{
if(num[j] > num[i]) temp++;
else temp--;
if(temp > 0) ans += cnt[temp + n];
else ans += cnt[-temp];
}
printf("%d",ans);
}
puts("");
}
}
int main()
{
solve();
return 0;
}
View
No changes.

0 comments on commit e3ec23a

Please sign in to comment.