結果
| 問題 |
No.945 YKC饅頭
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-08-03 01:03:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 445 ms / 2,000 ms |
| コード長 | 4,672 bytes |
| コンパイル時間 | 1,267 ms |
| コンパイル使用メモリ | 129,400 KB |
| 最終ジャッジ日時 | 2025-02-15 21:37:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 74 |
ソースコード
//yukicoder@cpp17
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <complex>
#include <cctype>
#include <utility>
#include <climits>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
/*
function corner below
*/
/*
Function corner above
*/
/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
*/
template< typename T, typename F>
struct LazySegmentTree{
private:
int n;
vector<T> node,lazy;
vector<bool> lazyTrigger;
F f;
T initer;
public:
LazySegmentTree(int n_, F f, T initer) : f(f),initer(initer) {
n = 1;
while(n < n_)n*=2;
node.resize(2*n-1, initer);
lazy.resize(2*n-1, {0,0,0});
lazyTrigger.resize(2*n-1, false);
}
void eval(int k, int l, int r){
if(lazyTrigger[k]){
node[k] = lazy[k];
if(r-l >= 1){
lazy[k*2+1] = lazy[k]/2;
lazyTrigger[k*2+1] = true;
lazy[k*2+2] = lazy[k]/2;
lazyTrigger[k*2+2] = true;
}
lazy[k] = {0,0,0};
lazyTrigger[k] = false;
}
}
//TODO: update -> apply(such as update and add)
void update(int a,int b, T x, int k = 0, int l = 0, int r = -1){
if(r < 0) r = n-1;
eval(k, l, r);
if(b < l || r < a){
return;
}
if(a <= l && r <= b){
lazy[k] = x*(r-l+1);
lazyTrigger[k] = true;
eval(k, l, r);
}else{
update(a,b,x,2*k+1, l, (l+r)/2);
update(a,b,x,2*k+2,(l+r)/2+1,r);
node[k] = f(node[k*2+1],node[k*2+2]);
}
}
T getf(int a,int b, int k=0, int l=0, int r=-1){
if(r < 0){
r = n-1;
}
if(r < a || b < l)return initer;
eval(k,l,r);
if(a <= l && r <= b){
return node[k];
}
T vl = getf(a,b,2*k+1,l,(l+r)/2);
T vr = getf(a,b,2*k+2,(l+r)/2+1,r);
return f(vl,vr);
}
void debug(){
int nw = 1;
int curr = 1;
cout << "---begin---" << endl;
for(int i = 0; 2*n-1 > i; i++){
cout << "(" << node[i] << ", " << lazy[i] << " (" << lazyTrigger[i] << ")) ";
if(nw == curr)cout << endl,nw *= 2, curr=1;
else curr++;
}
cout << "---end---" << endl;
}
};
template <typename T, typename F>
LazySegmentTree<T, F> get_lazy_segment_tree(int N, const F &f, T initer){
return LazySegmentTree{N,f,initer};
}
struct d{
int a,b,c;
d operator+(d x){
d ret;
ret.a = (*this).a + x.a;
ret.b = (*this).b + x.b;
ret.c = (*this).c + x.c;
return ret;
}
d operator*(int x){
d ret;
ret.a = (*this).a * x;
ret.b = (*this).b * x;
ret.c = (*this).c * x;
return ret;
}
d operator/(int x){
d ret;
ret.a = (*this).a / x;
ret.b = (*this).b / x;
ret.c = (*this).c / x;
return ret;
}
d operator+=(d a){return (*this) = (*this) + a;}
d operator*=(int a){return (*this) = (*this) * a;}
d operator/=(int a){return (*this) = (*this) / a;}
friend ostream &operator<<(ostream &os, const d &p){
return os << "(" << p.a << ", " << p.b << ". " << p.c << ")";
}
};
struct x{
int l,r;
char c;
};
int main(){
int n,m;cin>>n>>m;
d xx = {0,0,0};
auto seg = get_lazy_segment_tree(n, [](d a,d b){return a+b;}, xx);
vector<x> A(m);
for(int i = 0; m > i; i++){
cin>>A[i].l>>A[i].r>>A[i].c;
A[i].l--;A[i].r--;
}
reverse(A.begin(), A.end());
for(int i = 0; m > i; i++){
seg.update(A[i].l, A[i].r, {A[i].c == 'Y', A[i].c == 'K', A[i].c == 'C'});
}
auto z = seg.getf(0,n);
cout << z.a << " " << z.b << " " << z.c << endl;
return 0;
}