Submission #316910

#TimeUsernameProblemLanguageResultExecution timeMemory
316910anakib1Meetings (IOI18_meetings)C++17
19 / 100
4174 ms786436 KiB
//나는 가상 소녀들에게 큰 호감이 있습니다. #include <iostream> #include <cmath> #include <algorithm> #include <stdio.h> #include <cstring> #include <string> #include <cstdlib> #include <vector> #include <bitset> #include <map> #include <chrono> #include <functional> #include <unordered_set> #include <unordered_map> #include <numeric> #include <queue> #include <ctime> #include <stack> #include <set> #include <list> #include <deque> #include <iomanip> #include <sstream> #include <fstream> #include <stdarg.h> #include <utility> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define ull unisgned long long #define ld long double #define all(a) a.begin(), a.end() #define SORT(a) sort(all(a)) #define pii pair<int, int> #define tii triple<int, int, int> #define e 1e-7 #define PI acos(-1) #define sz(a) (int)(a.size()) #define inf 1e17 #define vi vector<int> #define F first #define S second #define rng(x) for(int _ = 0; _ < (x); _++) #define rngi(i, x) for(int i = 0; i < (x); i++) #define rngsi(s, i, x) for(int i = (s); i <(x); i++) #define problem "a" template<typename A, typename B, typename C> struct triple { A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {} }; template<typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { return triple<A, B, C>(a, b, c); } template<typename A, typename B, typename C> bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) { if (a.X != b.X) return a.X < b.X; if (a.Y != b.Y) return a.Y < b.Y; return a.Z < b.Z; } template<typename T, typename SS> ostream& operator<<(ostream& ofs, const pair<T, SS>& p) { ofs << "( " << p.F << " , " << p.S << " )"; return ofs; } template<typename T> void print(T a) { for (auto i : a) cout << i << ' '; cout << '\n'; } template<typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } template<typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } template<typename T, typename D> D min(T a) { return *min_element(all(a)); } template<typename T, typename D> D max(T a) { return *max_element(all(a)); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; #include "meetings.h" struct node { int pr, sf, ans; node(){pr = sf = ans = 0; } }; node mrg(const node& a, const node& b) { node res; res.pr = a.pr; res.sf = b.sf; res.ans = max(a.ans, b.ans, a.sf + b.pr); return res; } vector<node> t; void bld(int v, int l, int r, vi& a) { if (l > r)return; if (l == r)return void(t[v].pr = t[v].sf = t[v].ans = (a[l] == 1)); int m = l + r >> 1; bld(v << 1, l, m, a); bld(v << 1 | 1, m + 1, r, a); t[v] = mrg(t[v << 1], t[v << 1 | 1]); } node get(int v, int l, int r, int _l, int _r) { if (r < _l || _r < l)return node(); if (_l <= l && r <= _r)return t[v]; int m = l + r >> 1; return mrg(get(v << 1, l, m, _l, _r), get(v << 1 | 1, m + 1, r, _l, _r)); } std::vector<long long> minimum_costs(std::vector<int> h, std::vector<int> l, std::vector<int> r) { int n = sz(h), q = sz(l); bool s3 = 1; rngi(i, n) if (h[i] != 1 || h[i] != 2) s3 = 0; vector<ll> anss(q, inf); if (s3) { t.resize(4 * n); bld(1, 0, n - 1, h); rngi(i, q) anss[i] = (r[i] - l[i] + 1) * 2LL - get(1, 0, n - 1, l[i], r[i]).ans; } else { vector<vector<ll> > ans(n, vector<ll>(n)); rngi(i, n) { int v = h[i]; ans[i][i] = v; for (int j = i - 1; j >= 0; j--) { v = max(v, h[j]); ans[i][j] = v; } v = h[i]; for (int j = i + 1; j < n; j++) { v = max(v, h[j]); ans[i][j] = v; } partial_sum(all(ans[i]), ans[i].begin()); } auto s = [&](int x, int a, int b)->ll { return ans[x][b] - (a ? ans[x][a - 1] : 0LL); }; rngi(i, q) for (int j = l[i]; j <= r[i]; j++) anss[i] = min(anss[i], s(j, l[i], r[i])); } return anss; } /* * 4 2 2 4 3 5 0 2 1 3 */

Compilation message (stderr)

meetings.cpp: In function 'void bld(int, int, int, std::vector<int>&)':
meetings.cpp:122:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  122 |     int m = l + r >> 1;
      |             ~~^~~
meetings.cpp: In function 'node get(int, int, int, int, int)':
meetings.cpp:130:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  130 |     int m = l + r >> 1;
      |             ~~^~~
#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...