提出 #68152943


ソースコード 拡げる

#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC optimize(2)
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
//#undef ONLINE_JUDGE

namespace fastio
{
    const int bufl=1<<20;
    const double base1[16]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15};
    const double base2[16]={1,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,1e15};
    struct IN{
        FILE *IT;char ibuf[bufl],*is=ibuf,*it=ibuf;
        IN(){IT=stdin;}IN(char *a){IT=fopen(a,"r");}
        inline char getChar(){if(is==it){it=(is=ibuf)+fread(ibuf,1,bufl,IT);if(is==it)return EOF;}return *is++;}
        template<typename Temp>inline void getInt(Temp &a){a=0;int b=0,c=getChar();while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)a=(a<<1)+(a<<3)+c-48,c=getChar();if(b)a=-a;}
        template<typename Temp>inline void getDouble(Temp &a){a=0;int b=0,c=getChar(),d=0;__int128 e=0,f=0;while(c<48||c>57)b^=(c==45),c=getChar();while(c>=48&&c<=57)e=(e<<1)+(e<<3)+c-48,c=getChar();if(c==46){c=getChar();while(c>=48&&c<=57)d++,f=(f<<1)+(f<<3)+c-48,c=getChar();}a=e+base1[d]*f;if(b)a=-a;}
        IN& operator>>(char &a){a=getChar();return *this;}
        IN& operator>>(char *a){do{*a=getChar();}while(*a<=32);while(*a>32)*++a=getChar();*a=0;return *this;}
        IN& operator>>(string &a){char b=getChar();while(b<=32)b=getChar();while(b>32)a+=b,b=getChar();return *this;}
        IN& operator>>(int &a){getInt(a);return *this;}
        IN& operator>>(long long &a){getInt(a);return *this;}
        IN& operator>>(float &a){getDouble(a);return *this;}
        IN& operator>>(double &a){getDouble(a);return *this;}
        IN& operator>>(long double &a){getDouble(a);return *this;}
    };
    struct OUT{
        FILE *IT;char obuf[bufl],*os=obuf,*ot=obuf+bufl;int Eps;long double Acc;
        OUT(){IT=stdout,Eps=6,Acc=1e-6;}OUT(char *a){IT=fopen(a,"w"),Eps=6,Acc=1e-6;}
        inline void ChangEps(int x=6){Eps=x;}
        inline void flush(){fwrite(obuf,1,os-obuf,IT);os=obuf;}
        inline void putChar(int a){*os++=a;if(os==ot)flush();}
        template<typename Temp>inline void putInt(Temp a){if(a<0){putChar(45);a=-a;}if(a<10){putChar(a+48);return;}putInt(a/10);putChar(a%10+48);}
        template<typename Temp>inline void putLeading(Temp a,int b){if(!b)return;putLeading(a/10,b-1);putChar(a%10+48);}
        template<typename Temp>inline void putDouble(Temp a){if(a<0){putChar(45);a=-a;}__int128 b=a;putInt(b);a-=b;a*=base2[Eps];b=a+Acc;putChar(46);putLeading(b,Eps);}
        OUT& operator<<(char a){putChar(a);return *this;}
        OUT& operator<<(char *a){while(*a>32)putChar(*a++);return *this;}
        OUT& operator<<(int a){putInt(a);return *this;}
        OUT& operator<<(long long a){putInt(a);return *this;}
        OUT& operator<<(float a){putDouble(a);return *this;}
        OUT& operator<<(double a){putDouble(a);return *this;}
        OUT& operator<<(long double a){putDouble(a);return *this;}
        ~OUT(){flush();}
    };
}
using fastio::IN;
using fastio::OUT;
IN fin;
OUT fout;
#define cin fin
#define cout fout
#define int long long
void clear() {
}
int ans[500005];
mt19937 rnd(time(0));
struct ThisIsAValueSectionAddAndInsertZeroAndOnePointQueryValuesStructure {
	struct Info {
		int ls, rs, key, sz,vala, taga, mn;
	} t[2000001];
	int rt, tot;
	inline void push_up(int i) {
		if (!i) return;
		t[i].sz = t[t[i].ls].sz + t[t[i].rs].sz + 1;
		t[i].mn = min({t[i].vala, (t[i].ls ? t[t[i].ls].mn : 1ll << 61),(t[i].rs ? t[t[i].rs].mn : 1ll << 61)});
	}
	inline void settag(int i, int a) {
		if (!i) return;
		t[i].taga += a;
		t[i].vala += a;
		t[i].mn += a;
	}
	inline void push_down(int i) {
		if (!i) return;
		settag(t[i].ls, t[i].taga);
		settag(t[i].rs, t[i].taga);
		t[i].taga = 0;
	}
	inline void split(int u, int x, int &l, int &r) {
		if (!u) return l = r = 0, void();
		push_down(u);
		if (t[u].vala <= x) {
			l = u;
			split(t[u].rs, x, t[u].rs, r);
		} else {
			r = u;
			split(t[u].ls, x, l, t[u].ls);
		}
		push_up(u);
	}
	inline int merge(int x, int y) {
		push_down(x); push_down(y); push_up(x); push_up(y);
		if (!x || !y) return x | y;
		if (t[x].key < t[y].key) {
			t[x].rs = merge(t[x].rs, y);
			push_up(x);
			return x;
		} else {
			t[y].ls = merge(x, t[y].ls);
			push_up(y);
			return y;
		}
	}
	inline void output(int i, int fl) {
		if (!i) return;
		push_down(i);
		output(t[i].ls, fl);
		ans[i] = fl;
		output(t[i].rs, fl);
		push_up(i);
	}
	inline int make(int vala) {
		/*
		int ls, rs, key, sz, fa, vala, taga, valb, tagb, mn;
		*/
		t[++tot] = (Info){0, 0, rnd(), 1, vala, 0, vala};
		return tot;
	}
	inline int Merge(int les, int gre) {
		rt = 0;
		while (les && gre) {
			if (t[les].mn > t[gre].mn) swap(les, gre);
			int tmp;
			split(les, t[gre].mn, tmp, les);
			rt = merge(rt, tmp);
		}
		if (gre) rt = merge(rt, gre);
		if (les) rt = merge(rt, les);
		return rt;
	}
	inline void add(int x, int c) {
		settag(x, c);
	}
} t;
int n, l[500005], r[500005], x[500005], sz[500005], rt[500005];

void solve() {
	cin >> n;
	sz[1] = 1;
	sz[2] = 1;
	for (int i = 3; i <= n + 2; ++i) {
		cin >> l[i] >> r[i] >> x[i];
		l[i] += 1;
		r[i] += 1;
		sz[i] = sz[l[i]] + sz[r[i]];
		sz[i] = min(sz[i], 1ll << 61);
		rt[i] = t.make(x[i]);
	}
	for (int i = n + 2; i >= 3; --i) {
		int L, R;
		int mid = sz[l[i]];
		t.split(rt[i], mid, L, R);
		t.add(R, -mid);
		rt[l[i]] = t.Merge(rt[l[i]], L);
		rt[r[i]] = t.Merge(rt[r[i]], R);
	}
	t.output(rt[1], 0);
	t.output(rt[2], 1);
	for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
}


signed main() {
//	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int tc = 1;
//	cin >> tc;
	while (tc--) {
		clear();
		solve();
	}
	return 0;
}

提出情報

提出日時
問題 G - Binary Cat
ユーザ unr
言語 C++ 20 (gcc 12.2)
得点 625
コード長 7529 Byte
結果 AC
実行時間 4796 ms
メモリ 56548 KiB

コンパイルエラー

Main.cpp: In member function ‘long long int ThisIsAValueSectionAddAndInsertZeroAndOnePointQueryValuesStructure::make(long long int)’:
Main.cpp:157:44: warning: narrowing conversion of ‘rnd.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()()’ from ‘std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type’ {aka ‘long unsigned int’} to ‘long long int’ [-Wnarrowing]
  157 |                 t[++tot] = (Info){0, 0, rnd(), 1, vala, 0, vala};
      |                                         ~~~^~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 625 / 625
結果
AC × 1
AC × 56
セット名 テストケース
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random2_10.txt, random2_11.txt, random2_12.txt, random2_13.txt, random2_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3768 KiB
hand_00.txt AC 202 ms 56428 KiB
hand_01.txt AC 198 ms 56544 KiB
hand_02.txt AC 173 ms 56360 KiB
hand_03.txt AC 175 ms 56428 KiB
hand_04.txt AC 2625 ms 56480 KiB
hand_05.txt AC 4196 ms 56512 KiB
hand_06.txt AC 152 ms 56356 KiB
hand_07.txt AC 4404 ms 56476 KiB
hand_08.txt AC 162 ms 56468 KiB
hand_09.txt AC 1 ms 3756 KiB
random2_00.txt AC 150 ms 52784 KiB
random2_01.txt AC 915 ms 52440 KiB
random2_02.txt AC 1003 ms 56120 KiB
random2_03.txt AC 156 ms 54048 KiB
random2_04.txt AC 830 ms 53968 KiB
random2_05.txt AC 810 ms 53464 KiB
random2_06.txt AC 153 ms 53316 KiB
random2_07.txt AC 1119 ms 56076 KiB
random2_08.txt AC 1020 ms 52952 KiB
random2_09.txt AC 163 ms 52864 KiB
random2_10.txt AC 1261 ms 54368 KiB
random2_11.txt AC 1199 ms 53272 KiB
random2_12.txt AC 175 ms 53516 KiB
random2_13.txt AC 1531 ms 53316 KiB
random2_14.txt AC 1557 ms 54388 KiB
random_00.txt AC 308 ms 56352 KiB
random_01.txt AC 230 ms 56476 KiB
random_02.txt AC 927 ms 56356 KiB
random_03.txt AC 919 ms 56416 KiB
random_04.txt AC 4446 ms 56424 KiB
random_05.txt AC 272 ms 56320 KiB
random_06.txt AC 239 ms 56548 KiB
random_07.txt AC 4383 ms 56352 KiB
random_08.txt AC 920 ms 56296 KiB
random_09.txt AC 869 ms 56300 KiB
random_10.txt AC 252 ms 56476 KiB
random_11.txt AC 235 ms 56480 KiB
random_12.txt AC 837 ms 56316 KiB
random_13.txt AC 4394 ms 56296 KiB
random_14.txt AC 897 ms 56400 KiB
random_15.txt AC 276 ms 56516 KiB
random_16.txt AC 225 ms 56464 KiB
random_17.txt AC 856 ms 56472 KiB
random_18.txt AC 883 ms 56540 KiB
random_19.txt AC 4336 ms 56296 KiB
random_20.txt AC 286 ms 56324 KiB
random_21.txt AC 234 ms 56468 KiB
random_22.txt AC 4631 ms 56428 KiB
random_23.txt AC 937 ms 56540 KiB
random_24.txt AC 944 ms 56344 KiB
random_25.txt AC 306 ms 56300 KiB
random_26.txt AC 265 ms 56360 KiB
random_27.txt AC 916 ms 56508 KiB
random_28.txt AC 4796 ms 56344 KiB
random_29.txt AC 798 ms 56424 KiB