Submission #259966

# Submission time Handle Problem Language Result Execution time Memory
259966 2020-08-08T21:16:59 Z Kenzo_1114 Lottery (CEOI18_lot) C++17
0 / 100
484 ms 504 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
const int MAXQ = 110;

int n, l, Q, q[MAXN], a[MAXN], ans[MAXQ][MAXN], K[MAXN]; 

int main ()
{
	scanf("%d %d", &n, &l);

	for(int i = 1; i <= n; i++)	scanf("%d", &a[i]);

	scanf("%d", &Q);
	
	vector<pair<int, int> > qry;
	for(int i = 0, k; i < Q; i++)
	{
		scanf("%d", &k);
		qry.push_back(make_pair(k, i));
	}

	sort(qry.begin(), qry.end());

	for(int i = 0; i < Q; i++)	q[qry[i].second] = i;

	for(int k = 0, id = 0; k <= l; k++)	
	{
		if(k > qry[id].first)	id++;
		if(id >= qry.size())	break;
		K[k] = id;
	}

	for(int j = 1; j + l <= n; j++)
	{
		int k = 0;
		for(int i = 1; i <= l; i++) k += (a[i] != a[i + j]);

		ans[K[k]][1]++;
		ans[K[k]][1 + j]++;

//		printf("(1, %d) = %d\n", 1 + j, k);

		for(int i = 2; i + j + l - 1 <= n; i++)
		{
			k -= (a[i - 1] != a[i + j - 1]);
			k += (a[i + l - 1] != a[i + j + l - 1]);
			
//			printf("(%d, %d) = %d\n", i, i + j, k);

			ans[K[k]][i]++;
			ans[K[k]][i + j]++;
		}	
	}

	for(int i = 0; i < Q; i++)
		for(int j = 1; j <= n; j++)
			ans[i][j] += ans[i - 1][j];

	for(int i = 0; i < Q; i++)
	{
		for(int j = 1; j + l - 1 <= n; j++)	printf("%d ", ans[q[i]][j]);
		printf("\n");
	}
}

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:30:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(id >= qry.size()) break;
      ~~~^~~~~~~~~~~~~
lot.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &l);
  ~~~~~^~~~~~~~~~~~~~~~~
lot.cpp:12:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
                              ~~~~~^~~~~~~~~~~~~
lot.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
lot.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 484 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 484 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -