Submission #1012845

# Submission time Handle Problem Language Result Execution time Memory
1012845 2024-07-02T17:01:12 Z pan Lottery (CEOI18_lot) C++17
100 / 100
2599 ms 20240 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll a[10005], qq[105];
vector<ll> dis;
vector<vector<ll> >ans, ans2;
ll dp[10005];
int main()
{
	ll n, l, q;
	input2(n, l);
	for (ll i=0; i<n; ++i) input(a[i]);
	input(q);
	for (ll i=0; i<q; ++i) {input(qq[i]); dis.pb(qq[i]);}
	discretize(dis);
	ans.assign(dis.size(), vector<ll> (n, 0)); ans2.assign(dis.size(), vector<ll> (n, 0));
	for (ll x=0; x<2; ++x)
	{
		//show(x);
		fill(dp, dp+n, 0);
		vector<ll> now;
		for (ll i=0; i<l; ++i) for (ll j=1; j + i < n; ++j) dp[j] += (a[i]!=a[i+j]);
		for (ll j=1; j<=n-l; ++j) now.pb(dp[j]);
		sort(all(now));
		ll idx = -1;
		for (ll j=0; j<dis.size(); ++j)
		{
			while (idx + 1 < now.size() && dis[j] >= now[idx+1]) idx++;
			ans[j][0] += (idx+1);
		}
		for (ll i=1; i<=n-l; ++i)
		{
			now.clear();
			for (ll j=1; j + (i-1) < n; ++j) dp[j] -= (a[i-1]!=a[i-1+j]);
			for (ll j=1; j +( i+l-1) < n; ++j) dp[j] += (a[i+l-1]!=a[i+l-1+j]);
			for (ll j=1; j<=n-l-i; ++j) now.pb(dp[j]);
			sort(all(now));
	
			ll idx = -1;
			for (ll j=0; j<dis.size(); ++j)
			{
				while (idx + 1 < now.size() && dis[j] >= now[idx+1]) idx++;
				ans[j][i] += (idx+1);
			}
		}
		//for (ll i=0; i<dis.size(); ++i) for (ll j=0; j<=n-l; ++j) show(ans[i][j]);
		reverse(a, a+n);
		swap(ans, ans2);
	}
	//show(1);
	//for (ll i=0; i<dis.size(); ++i) for (ll j=0; j<=n-l; ++j) show(ans[i][j]);
	//for (ll i=0; i<dis.size(); ++i) for (ll j=0; j<=n-l; ++j) show(ans2[i][j]);
	for (ll i=0; i<dis.size(); ++i) for (ll j=0; j<=n-l; ++j){ ans[i][j] += ans2[i][n - (j+l-1) - 1]; }
	for (ll i=0; i<q; ++i)
	{
		ll j = lb(all(dis), qq[i])-dis.begin();
		for (ll k=0; k<n-l+1; ++k) print(ans[j][k], ' ');
		printf("\n");
	}
	//for (ll j=0; j<dis.size(); ++j) for (ll i=0; i<=n-l; ++i) show3(j, i, ans[j][i]);
	
	return 0;
}

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:59:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (ll j=0; j<dis.size(); ++j)
      |                ~^~~~~~~~~~~
lot.cpp:61:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    while (idx + 1 < now.size() && dis[j] >= now[idx+1]) idx++;
      |           ~~~~~~~~^~~~~~~~~~~~
lot.cpp:73:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (ll j=0; j<dis.size(); ++j)
      |                 ~^~~~~~~~~~~
lot.cpp:75:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     while (idx + 1 < now.size() && dis[j] >= now[idx+1]) idx++;
      |            ~~~~~~~~^~~~~~~~~~~~
lot.cpp:86:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for (ll i=0; i<dis.size(); ++i) for (ll j=0; j<=n-l; ++j){ ans[i][j] += ans2[i][n - (j+l-1) - 1]; }
      |               ~^~~~~~~~~~~
lot.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
lot.cpp:44:2: note: in expansion of macro 'input2'
   44 |  input2(n, l);
      |  ^~~~~~
lot.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
lot.cpp:45:25: note: in expansion of macro 'input'
   45 |  for (ll i=0; i<n; ++i) input(a[i]);
      |                         ^~~~~
lot.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
lot.cpp:46:2: note: in expansion of macro 'input'
   46 |  input(q);
      |  ^~~~~
lot.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
lot.cpp:47:26: note: in expansion of macro 'input'
   47 |  for (ll i=0; i<q; ++i) {input(qq[i]); dis.pb(qq[i]);}
      |                          ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 60 ms 660 KB Output is correct
14 Correct 21 ms 1120 KB Output is correct
15 Correct 20 ms 860 KB Output is correct
16 Correct 37 ms 1164 KB Output is correct
17 Correct 29 ms 1180 KB Output is correct
18 Correct 29 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1663 ms 1160 KB Output is correct
2 Correct 1838 ms 988 KB Output is correct
3 Correct 1389 ms 928 KB Output is correct
4 Correct 1014 ms 988 KB Output is correct
5 Correct 371 ms 948 KB Output is correct
6 Correct 903 ms 1040 KB Output is correct
7 Correct 312 ms 944 KB Output is correct
8 Correct 568 ms 1112 KB Output is correct
9 Correct 1099 ms 1056 KB Output is correct
10 Correct 1077 ms 1028 KB Output is correct
11 Correct 135 ms 572 KB Output is correct
12 Correct 1400 ms 928 KB Output is correct
13 Correct 683 ms 956 KB Output is correct
14 Correct 858 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1663 ms 1160 KB Output is correct
2 Correct 1838 ms 988 KB Output is correct
3 Correct 1389 ms 928 KB Output is correct
4 Correct 1014 ms 988 KB Output is correct
5 Correct 371 ms 948 KB Output is correct
6 Correct 903 ms 1040 KB Output is correct
7 Correct 312 ms 944 KB Output is correct
8 Correct 568 ms 1112 KB Output is correct
9 Correct 1099 ms 1056 KB Output is correct
10 Correct 1077 ms 1028 KB Output is correct
11 Correct 135 ms 572 KB Output is correct
12 Correct 1400 ms 928 KB Output is correct
13 Correct 683 ms 956 KB Output is correct
14 Correct 858 ms 960 KB Output is correct
15 Correct 2403 ms 928 KB Output is correct
16 Correct 907 ms 1032 KB Output is correct
17 Correct 1232 ms 1028 KB Output is correct
18 Correct 1020 ms 1268 KB Output is correct
19 Correct 1035 ms 972 KB Output is correct
20 Correct 1070 ms 1024 KB Output is correct
21 Correct 1080 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 60 ms 660 KB Output is correct
14 Correct 21 ms 1120 KB Output is correct
15 Correct 20 ms 860 KB Output is correct
16 Correct 37 ms 1164 KB Output is correct
17 Correct 29 ms 1180 KB Output is correct
18 Correct 29 ms 1116 KB Output is correct
19 Correct 1663 ms 1160 KB Output is correct
20 Correct 1838 ms 988 KB Output is correct
21 Correct 1389 ms 928 KB Output is correct
22 Correct 1014 ms 988 KB Output is correct
23 Correct 371 ms 948 KB Output is correct
24 Correct 903 ms 1040 KB Output is correct
25 Correct 312 ms 944 KB Output is correct
26 Correct 568 ms 1112 KB Output is correct
27 Correct 1099 ms 1056 KB Output is correct
28 Correct 1077 ms 1028 KB Output is correct
29 Correct 135 ms 572 KB Output is correct
30 Correct 1400 ms 928 KB Output is correct
31 Correct 683 ms 956 KB Output is correct
32 Correct 858 ms 960 KB Output is correct
33 Correct 2403 ms 928 KB Output is correct
34 Correct 907 ms 1032 KB Output is correct
35 Correct 1232 ms 1028 KB Output is correct
36 Correct 1020 ms 1268 KB Output is correct
37 Correct 1035 ms 972 KB Output is correct
38 Correct 1070 ms 1024 KB Output is correct
39 Correct 1080 ms 1268 KB Output is correct
40 Correct 2558 ms 4648 KB Output is correct
41 Correct 75 ms 3924 KB Output is correct
42 Correct 1425 ms 4640 KB Output is correct
43 Correct 1033 ms 4332 KB Output is correct
44 Correct 1035 ms 4376 KB Output is correct
45 Correct 2599 ms 20216 KB Output is correct
46 Correct 84 ms 16672 KB Output is correct
47 Correct 1333 ms 20240 KB Output is correct
48 Correct 1047 ms 16724 KB Output is correct
49 Correct 1057 ms 17404 KB Output is correct