Submission #41434

#TimeUsernameProblemLanguageResultExecution timeMemory
41434grumpy_gordonArranging Tickets (JOI17_arranging_tickets)C++14
0 / 100
1 ms376 KiB
/* .:*+=%@@@@@@=-. .:=@#@@@#@@#######%==*. .-=####@######%*-.....:%##%. .*@###########%+:--........-%@- .*@##############@+--.........-:%- .+##################@==%%%%=+*:----+. .-@####################%++%@@@@@=+**%@@* .%###################@%%@@@###@%+:--%@@%. -@###################@%%%%*::*%++:-----=@+. -#####################@%=++++++*:-------.-=: .+####################@%++*::-:::--::*:::***=: .@#####################%=++*::::-:::++*=##@@#@- ..#####################@%%=++**:::::**+%@#@%%##-.. .%####################@@%=+++*+****::*=@######@. .=######################@%%==+==++**+=@%@##@###+:... -#######################@@@%%%===++=@@@%=++===*::--... -########################@@@@@@@%==%%=++==@@:::::*:--. ..:#########################@@@@@@%%======++++::-..:-.--... %#############################@###@%%@@%==%=%*----.--.::---. #############################################*-:*:-:---*---- . #############################################*--*--:---*---:-. #############################################+--::--::-*::-::. ###########################################+:*-.---.---.:---*-.. ###########################################**:-----------------. ##########################################@::**:--::::::--:::::- ###########################################:--:*:::::::::**::*+* ###########################################=:::***::::::**:::*+* ############################@@@@@@#########@+****::::********+++ ############################@%%%%%@@@@@@@###%+***::::::::***+==+ ############################@%%%%%%%%%%%@####=+:::-::::-::*+=%%+ #############################@%%%%%%%%%%@#####=::--------:*=%@%+ %###########################@%%%%==%%%%%%@##@#=:------..-:+%@@%= ---------------------------------------------- -------------------------------------------- ---------------------------------------------- -------------------------------------------- ---------------------------------------------- o###########oo o##" ""##o o#" "## o#" "#o #" ## ## "## #" ## # ################### # # # # # # # # # # # # # #o # "#o ## "#o ## "#o o#" "#o ## "#o o#" "#ooo ooo#######oo ############### "######o o###"" "###o # ### o###o oooo ### oo####" o###**# #**# ############" ""##""""""""""########### # # oooooooo#"#** ## # # # # # ** ## # #o# #o# *****###ooo# ## ## o###o ## o##***## o########## #***#**##o o##" ""### #***##***# o#######o ### oo#### ##**####*# o##" ""#############"" ##****### ##" ## ##*##*### ## ### ##### ## ## ### # ## # ## ## # ## ## ## ### ## ###oo ### ""### ### ### */ #include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") //#pragma GCC target("avx,tune=native") //float __attribute__((aligned(32))) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; int mysqrt(ll x){ int l = 0, r = 1e9 + 1; while (r - l > 1){ int m = (l + r) / 2; if (m * (ll)m <= x) l = m; else r = m; } return l; } mt19937 rnd(1337); ll AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993; ll myrand(){ ll ZR = (XR * AR + YR * BR + CR) % MODR; XR = YR; YR = ZR; return ZR; } const int Mod = 1e9 + 7; int bpow(int x, int y){ if (y == 0) return 1; if (y == 1) return x; int ret = bpow(x, y >> 1); ret = (ret * (ll)ret) % Mod; if (y & 1) ret = (ret * (ll)x) % Mod; return ret; } int bdiv(int x, int y){ return (x * (ll)bpow(y, Mod - 2)) % Mod; } void setmin(int &x, int y){ x = min(x, y); } void setmax(int &x, int y){ x = max(x, y); } void setmin(ll &x, ll y){ x = min(x, y); } void setmax(ll &x, ll y){ x = max(x, y); } int gcd(int a, int b){ return a ? gcd(b % a, a) : b; } const ll llinf = 2e18 + 100; const double eps = 1e-9; const int maxn = 2e5 + 100, maxw = 1e6 + 100, inf = 2e9 + 100, sq = 300, mod = 1e9 + 7, LG = 17; int n, m; pair<pair<int, int>, int> seg[maxn]; pair<int, int> que[maxn]; ll p[maxn]; int rem[maxn]; bool check(ll k){ for (int i = 0; i < n; i++) p[i] = 0; for (int i = 1; i <= m; i++) rem[i] = seg[i].second; set<pair<int, int> > g; ll now = 0; int it = 0; while (it < 2 * m){ int last = it; while (it < 2 * m && que[it].first == que[last].first){ int id = abs(que[it].second); if (que[it].second > 0){ g.insert(make_pair(seg[id].first.second, id)); now += rem[id]; } else{ if (g.find(make_pair(seg[id].first.second, id)) != g.end()) g.erase(make_pair(seg[id].first.second, id)), now -= rem[id]; } it++; } while (now > k){ int id = g.rbegin()->second; if (rem[id] > now - k) rem[id] -= now - k; else now -= rem[id], rem[id] = 0, g.erase(make_pair(seg[id].first.second, id)); } } for (int i = 1; i <= m; i++){ p[seg[i].first.first] += rem[i]; p[seg[i].first.second] -= rem[i]; p[0] += seg[i].second - rem[i]; p[seg[i].first.first] -= seg[i].second - rem[i]; p[seg[i].first.second] += seg[i].second - rem[i]; } ll val = 0; for (int i = 0; i < n; i++){ val += p[i]; if (val > k) return 0; } return 1; } int main() { #ifdef ONPC //ifstream cin("a.in"); //ofstream cout("a.out"); freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #else //ifstream cin("sprinklers.in"); //ofstream cout("sprinklers.out"); //freopen("road.in", "r", stdin); //freopen("road.out", "w", stdout); #endif // ONPC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll SUM = 0; cin >> n >> m; for (int i = 1; i <= m; i++){ cin >> seg[i].first.first >> seg[i].first.second >> seg[i].second; SUM += seg[i].second; seg[i].first.first--; seg[i].first.second--; if (seg[i].first.first > seg[i].first.second) swap(seg[i].first.first, seg[i].first.second); que[2 * (i - 1)] = make_pair(seg[i].first.first, i); que[2 * (i - 1) + 1] = make_pair(seg[i].first.second, -i); } sort(que, que + 2 * m); ll l = 0, r = SUM; while (r - l > 1){ ll med = (l + r) / 2; if (check(med)) r = med; else l = med; } cout << r; }
#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...