結果
| 問題 |
No.945 YKC饅頭
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-08 10:07:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 1,357 bytes |
| コンパイル時間 | 582 ms |
| コンパイル使用メモリ | 50,888 KB |
| 最終ジャッジ日時 | 2025-01-08 09:41:39 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 74 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | int N, M; scanf("%d%d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:52:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | int a, b; char c; scanf("%d %d %c", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdint>
#include <cstdio>
#include <vector>
using namespace std;
using i64 = int64_t;
template <class T>
struct SegTree {
int N;
vector<T> dat;
explicit SegTree(int n) {
N = 1;
while(N < n) { N <<= 1; }
N <<= 1;
dat.assign(N, 0);
}
void update(int a, int b, int k, int l, int r, int x) {
if(k >= N) { return; }
if(dat[k] != 0) { return; }
if(b <= l || r <= a) { return; }
update(a, b, 2*k+0, l, (l+r)/2, x);
update(a, b, 2*k+1, (l+r)/2, r, x);
if(a <= l && r <= b) {
if(l+1 == r || (dat[2*k] == x && dat[2*k+1] == x)) {
dat[k] = x;
}
}
}
void update(int a, int b, int x) {
update(a, b, 1, 0, N/2, x);
}
void dump() {
for(int i=0; i<N; ++i) {
if(i) { fprintf(stderr, " "); }
fprintf(stderr, "%d", dat[i]);
}
fprintf(stderr, "\n");
}
void solve() {
vector<int> v(4);
for(int i=N/2; i<N; ++i) {
++v[dat[i]];
}
printf("%d %d %d\n", v[1], v[2], v[3]);
}
};
int main(void) {
int N, M; scanf("%d%d", &N, &M);
SegTree<int> tree(N);
for(int i=0; i<M; ++i) {
int a, b; char c; scanf("%d %d %c", &a, &b, &c);
int x = 1;
switch(c) {
case 'K':
x = 2;
break;
case 'C':
x = 3;
break;
}
--a;
tree.update(a, b, x);
}
tree.solve();
return 0;
}