Submission #1012845

#TimeUsernameProblemLanguageResultExecution timeMemory
1012845panLottery (CEOI18_lot)C++17
100 / 100
2599 ms20240 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...