Submission #73105877


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int a[400005],b[400005],t;


signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ans = 1;
	b[++t] = a[1];
	int maxd = a[1],mind = a[1];
	int h = 1;
	for (int i = 2; i <= n; i++) {
		int x = lower_bound (b + h,b + t + 1,a[i]) - b;
		int y = upper_bound (b + h,b + t + 1,a[i]) - b;
		if (a[i] - x < m) {
			h = x + 1;
		}
		if (y - a[i] < m) {
			h = y + 1;
		}
		ans += h - t;
		b[++t] = a[i];
		for (int j = t; j >= h; j--) {
			if (b[j] < b[j - 1]) swap(b[j],b[j - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task E - Sparse Range
User chenzehan
Language C++23 (GCC 15.2.0)
Score 0
Code Size 647 Byte
Status WA
Exec Time 96 ms
Memory 9936 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:13:13: warning: unused variable 'maxd' [-Wunused-variable]
   13 |         int maxd = a[1],mind = a[1];
      |             ^~~~
./Main.cpp:13:25: warning: unused variable 'mind' [-Wunused-variable]
   13 |         int maxd = a[1],mind = a[1];
      |                         ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 1
WA × 2
AC × 2
WA × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min1.txt, min2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
min1.txt AC 1 ms 3488 KiB
min2.txt WA 1 ms 3416 KiB
random_01.txt WA 94 ms 9840 KiB
random_02.txt WA 79 ms 8740 KiB
random_03.txt WA 94 ms 9844 KiB
random_04.txt WA 82 ms 9104 KiB
random_05.txt WA 94 ms 9880 KiB
random_06.txt WA 55 ms 7300 KiB
random_07.txt WA 94 ms 9840 KiB
random_08.txt WA 69 ms 8244 KiB
random_09.txt WA 94 ms 9936 KiB
random_10.txt WA 63 ms 7796 KiB
random_11.txt WA 76 ms 8736 KiB
random_12.txt WA 21 ms 4932 KiB
random_13.txt WA 96 ms 9936 KiB
random_14.txt WA 95 ms 9644 KiB
random_15.txt WA 95 ms 9684 KiB
random_16.txt WA 95 ms 9664 KiB
sample_01.txt AC 1 ms 3636 KiB
sample_02.txt WA 1 ms 3600 KiB
sample_03.txt WA 1 ms 3620 KiB