Submission #140533

# Submission time Handle Problem Language Result Execution time Memory
140533 2019-08-03T12:31:23 Z luciocf Street Lamps (APIO19_street_lamps) C++14
40 / 100
1102 ms 8964 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;

struct Op
{
	int type;
	int ind;
} query[maxn];

int n, q;

int last[maxn];
int ans[maxn];

bool on[maxn];
bool mark[maxn];

void solve_small(void)
{
	for (int i = 1; i <= q; i++)
	{
		string op;
		cin >> op;

		if (op == "toggle")
		{
			int ind;
			scanf("%d", &ind);

			query[i] = {0, ind};
		}
		else
		{
			int l, r;
			scanf("%d %d", &l, &r);

			query[i] = {1, -1};

			int ans = 0;
			for (int j = 1; j <= n; j++)
				mark[j] = on[j];

			for (int j = 1; j <= i; j++)
			{
				if (query[j].type == 1)
				{
					bool ok = 1;
					for (int k = l; k < r; k++)
						if (!mark[k])
							ok = 0;

					if (ok) ans++;
				}
				else
				{

					bool ok = 1;
					for (int k = l; k < r; k++)
						if (!mark[k])
							ok = 0;

					if (ok) ans++;

					mark[query[j].ind] = !mark[query[j].ind];
				}
			}

			printf("%d\n", ans);
		}
	}
}

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

	for (int i = 1; i <= n; i++)
	{
		char x;
		scanf(" %c", &x);

		if (x == '1') on[i] = true;
	}

	if (n <= 100 && q <= 100)
	{
		solve_small();
		return 0;
	}

	for (int i = 1; i <= q; i++)
	{
		string op;
		cin >> op;

		if (op == "toggle")
		{
			int ind;
			scanf("%d", &ind);

			on[ind] = !on[ind];

			if (!on[ind])
				ans[ind] += (i-last[ind]);

			last[ind] = i;
		}
		else
		{
			int l, r;
			scanf("%d %d", &l, &r);

			int tot = ans[l];

			if (on[l]) tot += (i-last[l]);

			printf("%d\n", tot);
		}
	}
}

Compilation message

street_lamps.cpp: In function 'void solve_small()':
street_lamps.cpp:31:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &ind);
    ~~~~~^~~~~~~~~~~~
street_lamps.cpp:38:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &l, &r);
    ~~~~~^~~~~~~~~~~~~~~~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~
street_lamps.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &x);
   ~~~~~^~~~~~~~~~~
street_lamps.cpp:102:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &ind);
    ~~~~~^~~~~~~~~~~~
street_lamps.cpp:114:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &l, &r);
    ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 634 ms 4328 KB Output is correct
2 Correct 637 ms 4764 KB Output is correct
3 Correct 648 ms 5496 KB Output is correct
4 Correct 705 ms 8964 KB Output is correct
5 Correct 782 ms 8204 KB Output is correct
6 Correct 612 ms 8564 KB Output is correct
7 Correct 1089 ms 7132 KB Output is correct
8 Correct 1102 ms 8748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 634 ms 4328 KB Output is correct
9 Correct 637 ms 4764 KB Output is correct
10 Correct 648 ms 5496 KB Output is correct
11 Correct 705 ms 8964 KB Output is correct
12 Correct 782 ms 8204 KB Output is correct
13 Correct 612 ms 8564 KB Output is correct
14 Correct 1089 ms 7132 KB Output is correct
15 Correct 1102 ms 8748 KB Output is correct
16 Incorrect 3 ms 376 KB Output isn't correct
17 Halted 0 ms 0 KB -