제출 #433688

#제출 시각아이디문제언어결과실행 시간메모리
433688JeanBombeur가로등 (APIO19_street_lamps)C++17
20 / 100
255 ms19312 KiB
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

//   <|°_°|>

const int MAX_LAMPES = (300 * 1000);

bool State[MAX_LAMPES];

char Mot[MAX_LAMPES + 1];

vector <int> Dates[MAX_LAMPES];

int nbLampes, nbRequetes;

void Read() {
	scanf("%d %d", &nbLampes, &nbRequetes);
	scanf("%s", Mot);
	for (int i = 0; i < nbLampes; i ++)
	{
		State[i] = Mot[i] == '1';
		Dates[i].push_back(0);
	}
	return;
}

void Solve() {
	for (int i = 1; i <= nbRequetes; i ++)
	{
		int a, b;
		scanf("%s %d", Mot, &a);
		a --;
		Dates[a].push_back(i);
		if (Mot[0] == 'q')
		{
			scanf("%d", &b);
			b --;
			int sz = (int)Dates[a].size();
			int ans = 0;
			int deb = 1;
			if (!State[a])
				deb ++;
			for (; deb < sz; deb += 2)
			{
				ans += Dates[a][deb] - Dates[a][deb - 1];
			}
			printf("%d\n", ans);
			if (!State[a])
				ans = i - ans;
			Dates[a].clear();
			Dates[a].push_back(0);
			Dates[a].push_back(ans);
			if (!(sz & 1))
				Dates[a].push_back(i);
		}
	}
	return;
}

int main() {
	Read();
	Solve();
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

street_lamps.cpp: In function 'void Read()':
street_lamps.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d %d", &nbLampes, &nbRequetes);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%s", Mot);
      |  ~~~~~^~~~~~~~~~~
street_lamps.cpp: In function 'void Solve()':
street_lamps.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%s %d", Mot, &a);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
street_lamps.cpp:38:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |    scanf("%d", &b);
      |    ~~~~~^~~~~~~~~~
#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...