QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385343#3765. Make Rounddog *Very* Happyucup-team1251WA 651ms19616kbC++202.7kb2024-04-10 17:52:172024-04-10 17:52:17

Judging History

你现在查看的是最新测评结果

  • [2024-04-10 17:52:17]
  • 评测
  • 测评结果:WA
  • 用时:651ms
  • 内存:19616kb
  • [2024-04-10 17:52:17]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
#define endl "\n"
#define pb push_back_back
#define ll long long
// #define int long long
#define pii pair<ll,ll>
#define psi pair<string, ll>
#define de cout<<1;
#define mem(a,x) memset(a,x,sizeof a)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int mod1=998244353;
const int mod2=1e9+7;
const int N = 1e6 + 60;
int n, m;
int a[N];
int r[N], l[N], ans[N];
// struct node
// {
// 	int l, r, s, add;
// }tr[N << 2];
// void push_backup(int u)
// {
// 	tr[u].s = (tr[u << 1].s + tr[u << 1 | 1].s);
// }
// void push_backdown(int u)
// {
// 	if(tr[u].add)
// 	{
// 		tr[u << 1].add += tr[u].add;
// 		tr[u << 1 | 1].add += tr[u].add;
// 		tr[u << 1].s += (tr[u << 1].r - tr[u << 1].l + 1) * tr[u].add;
// 		tr[u << 1 | 1].s += (tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1) * tr[u].add;
// 		tr[u].add = 0;
// 	}
// }
// void build(int u, int l, int r)
// {
// 	tr[u] = {l, r};
// 	if(l == r) return;
// 	int mid = l + r >> 1;
// 	build(u << 1, l, mid);
// 	build(u << 1 | 1,mid + 1, r);
// }
// void modify(int u, int l, int r)
// {
// 	if(tr[u].l >= l && tr[u].r <= r)
// 	{
// 		tr[u].s ++ ;
// 		tr[u].add ++ ;
// 		return;
// 	}
// 	push_backdown(u);
// 	int mid = tr[u].l + tr[u].r >> 1;
// 	if(l <= mid) modify(u << 1, l, r);
// 	if(r > mid) modify(u << 1 | 1, l, r);
// 	push_backup(u);
// } 
// void ask(int u)
// {
// 	if(tr[u].l == tr[u].r) 
// 	{
// 		ans[tr[u].l] = tr[u].s;
// 		return;
// 	}
// 	push_backdown(u);
// 	ask(u << 1);
// 	ask(u << 1 | 1);
// } 
void solve()
{
	while(scanf("%d%d", &n, &m) != EOF)
	{
		rep(i, 1, n)
		{
			scanf("%d", &a[i]);
		}
		//build(1, 1, n);
		vector<int>s;
		pre(i, n, 1)
		{
			if(s.empty()) s.push_back(i);
			else
			{
				while(s.size() && a[i] > a[s.back()])
				{
					l[s.back()] = i;
					s.pop_back();
				}
				s.push_back(i);
			}
		}
		while(s.size()) l[s.back()] = 0, s.pop_back();
		rep(i, 1, n)
		{
			if(s.empty()) s.push_back(i);
			else
			{
				while(s.size() && a[i] > a[s.back()])
				{
					r[s.back()] = i;
					s.pop_back();
				}
				s.push_back(i);
			}
		}
		while(s.size()) r[s.back()] = n + 1, s.pop_back();
		rep(i, 1, n)
		{
			int tr = r[i] - 1;
			rep(j, l[i] + 1, i)
			{
				tr = r[i] - 1;
				int now = a[i] + j - 1 - m;
				tr = min(tr, now);
				if(tr < i) continue;
				else
				{
					ans[i] ++ ;
                    ans[tr + 1] -- ;
				}
			}
		}
		rep(i, 1, n) ans[i] += ans[i - 1];
		rep(i, 1, n) printf("%d ", ans[i]);
		rep(i, 0, n + 1) ans[i] = 0;
		printf("\n");
	}
}
int main()
{
	//IOS;
	int _;
	//cin >> _;
	_ = 1;
	while(_ -- )
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 651ms
memory: 19616kb

input:

3 0
1 3 2
3 1
1 3 2
5 2
1 2 3 4 5
10 4
9 9 5 4 4 1 2 8 5 2
10 0
9 4 5 2 5 8 3 4 5 4
10 -2
5 10 10 3 6 6 10 2 4 5
10 0
1 10 2 5 8 3 7 2 2 3
10 8
10 1 4 8 8 4 2 1 6 2
10 -10
6 7 6 9 6 10 4 6 4 5
10 9
2 6 7 10 2 1 2 2 10 7
10 -6
8 9 2 10 7 2 1 8 6 1
10 8
6 10 2 8 1 7 8 8 8 9
10 -1
4 9 8 4 2 10 6 5 9 5
...

output:

1 2 3 
0 2 2 
0 0 1 2 3 
1 3 4 3 3 1 0 4 4 2 
1 2 3 4 7 6 7 8 9 8 
1 2 5 6 7 10 12 13 14 15 
1 2 3 4 5 6 7 8 10 10 
1 1 0 0 0 0 0 0 0 0 
1 2 3 4 5 6 7 8 9 10 
0 0 0 1 0 0 0 0 1 0 
1 2 3 4 5 6 7 8 9 10 
0 2 1 0 0 0 0 0 0 1 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 9 10 12 12 16 
1 2 3 4 5 6 9 14 15 16 
1 3 3 ...

result:

wrong answer 4th lines differ - expected: '1 2 3 2 2 1 0 4 4 2', found: '1 3 4 3 3 1 0 4 4 2 '