結果
問題 | No.2408 Lakes and Fish |
ユーザー | marc2825 |
提出日時 | 2023-08-28 23:34:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 10,104 bytes |
コンパイル時間 | 2,810 ms |
コンパイル使用メモリ | 226,420 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-09 18:04:47 |
合計ジャッジ時間 | 6,173 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 48 ms
6,940 KB |
testcase_05 | AC | 46 ms
6,944 KB |
testcase_06 | AC | 49 ms
6,940 KB |
testcase_07 | AC | 61 ms
6,940 KB |
testcase_08 | AC | 62 ms
6,940 KB |
testcase_09 | AC | 57 ms
6,944 KB |
testcase_10 | AC | 59 ms
6,944 KB |
testcase_11 | AC | 33 ms
6,944 KB |
testcase_12 | AC | 44 ms
6,944 KB |
testcase_13 | AC | 11 ms
6,940 KB |
testcase_14 | AC | 26 ms
6,940 KB |
testcase_15 | AC | 46 ms
6,940 KB |
testcase_16 | AC | 16 ms
6,940 KB |
testcase_17 | AC | 14 ms
6,940 KB |
testcase_18 | AC | 28 ms
6,944 KB |
testcase_19 | AC | 46 ms
6,944 KB |
testcase_20 | AC | 43 ms
6,940 KB |
testcase_21 | AC | 44 ms
6,940 KB |
ソースコード
//#pragma GCC target ("avx") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #ifdef MARC_LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; //#define int long long using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vvvvll = vector<vvvll>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>; using ld = long double; using vld = vector<ld>; using vvld = vector<vld>; using vd = vector<double>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using pii = pair<int, int>; using pcc = pair<char, char>; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pdd = pair<double, double>; using pldld = pair<ld,ld>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vpll = vector<pll>; using vvpll = vector<vpll>; using vpldld = vector<pldld>; template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>; #define vec(type, name, ...) vector<type> name(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type> > name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type> > > name(h, vector<vector<type> >(w, vector<type>(__VA_ARGS__))) #define vvvv(type, name, a, b, c, ...) vector<vector<vector<vector<type> > > > name(a, vector<vector<vector<type> > >(b, vector<vector<type> >(c, vector<type>(__VA_ARGS__)))) #define overload4(a,b,c,d,name,...) name #define rep1(n) for(ll i = 0; i < (ll)n; i++) #define rep2(i,n) for(ll i = 0; i < (ll)n; i++) #define rep3(i,a,b) for (ll i = a; i < (ll)b; i++) #define rep4(i,a,b,c) for (ll i = a; i < (ll)b; i += (ll)c) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define repback1(n) for (ll i = (ll)n-1; i >= 0; i--) #define repback2(i,n) for (ll i = (ll)n-1; i >= 0; i--) #define repback3(i,a,b) for (ll i = (ll)b-1; i >= (ll)a; i--) #define repback4(i,a,b,c) for (ll i = (ll)b-1; i >= (ll)a; i -= (ll)c) #define repback(...) overload4(__VA_ARGS__,repback4,repback3,repback2,repback1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define include(y, x, H, W) (0 <= x && x < W && 0 <= y && y < H) #define square(x) (x) * (x) #define pb push_back #define eb emplace_back #define fir first #define sec second #define equals(a,b) (fabs((a) - (b)) < EPS) #define TIMER_START TIME_START = clock() #ifdef MARC_LOCAL #define debug1(x) cout << "debug: " << (#x) << ": " << (x) << endl #define debug2(x, y) cout << "debug: " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << endl #define debug3(x, y, z) cout << "debug: " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << endl #define debug4(x, y, z, w) cout << "debug: " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << endl #define debug5(x, y, z, w, v) cout << "debug: " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << ", " << (#v) << ": " << (v) << endl #define debug6(x, y, z, w, v, u) cout << "debug: " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << ", " << (#v) << ": " << (v) << ", " << (#u) << ": " << (u) << endl #define overload6(a, b, c, d, e, f, g,...) g #define debug(...) overload6(__VA_ARGS__, debug6, debug5, debug4, debug3, debug2, debug1)(__VA_ARGS__) #define debuga cerr << "a" << endl #define debugnl cout << endl; #define Case(i) cout << "Case #" << (i) << ": " #define TIMECHECK cerr << 1000.0 * static_cast<double>(clock() - TIME_START) / CLOCKS_PER_SEC << "ms" << endl #else #define debug1(x) void(0) #define debug2(x, y) void(0) #define debug3(x, y, z) void(0) #define debug4(x, y, z, w) void(0) #define debug5(x, y, z, w, v) void(0) #define debug6(x, y, z, w, v, u) void(0) #define debug(...) void(0) #define debuga void(0) #define debugnl void(0) #define Case(i) void(0) #define TIMECHECK void(0) #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); clock_t TIME_START; const long double pi = 3.1415926535897932; const long long INFL = 1000000000000000000ll; const long long INFLMAX = numeric_limits< long long >::max(); // 9223372036854775807 const int INF = 1000000000; const int INFMAX = numeric_limits< int >::max(); // 2147483647 const long double INFD = numeric_limits<ld>::infinity(); const long double EPS = 1e-9; const int mod1 = 1000000007; const int mod2 = 998244353; const vi dx1 = {1,0,-1,0}; const vi dy1 = {0,1,0,-1}; const vi dx2 = {0, 1, 1, 1, 0, -1, -1, -1, 0}; const vi dy2 = {1, 1, 0, -1, -1, -1, 0, 1, 1}; const char nl = '\n'; template<typename T> ostream& operator << (ostream& os, vector<T>& vec) { os << "["; for (int i = 0; i<vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "]"; return os; } /// vector 出力 template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // pair 出力 template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) { os << "{"; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // map出力 template<typename T> ostream& operator << (ostream& os, set<T>& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } /// set 出力 template<typename T> void print(const T& x, const char endch = ' ') { cout << x << endch; } ll popcnt(unsigned long long a){ return __builtin_popcountll(a); } // ll は 64bit対応! template<class T>void UNIQUE(T& A) {sort(all(A)); A.erase(unique(all(A)), A.end());} template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); } template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); } void YESNO(bool b) {if(b){cout<<"YES"<<'\n';} else{cout<<"NO"<<'\n';}} void YES() {YESNO(true);} void NO() {YESNO(false);} void yesno(bool b) {if(b){cout<<"yes"<<'\n';} else{cout<<"no"<<'\n';}} void yes() {yesno(true);} void no() {yesno(false);} void YesNo(bool b) {if(b){cout<<"Yes"<<'\n';} else{cout<<"No"<<'\n';}} void Yes() {YesNo(true);} void No() {YesNo(false);} void POSIMPOS(bool b) {if(b){cout<<"POSSIBLE"<<'\n';} else{cout<<"IMPOSSIBLE"<<'\n';}} void PosImpos(bool b) {if(b){cout<<"Possible"<<'\n';} else{cout<<"Impossible"<<'\n';}} void posimpos(bool b) {if(b){cout<<"possible"<<'\n';} else{cout<<"impossible"<<'\n';}} void FIRSEC(bool b) {if(b){cout<<"FIRST"<<'\n';} else{cout<<"SECOND"<<'\n';}} void firsec(bool b) {if(b){cout<<"first"<<'\n';} else{cout<<"second"<<'\n';}} void FirSec(bool b) {if(b){cout<<"First"<<'\n';} else{cout<<"Second"<<'\n';}} void AliBob(bool b) {if(b){cout<<"Alice"<<'\n';} else{cout<<"Bob"<<'\n';}} void TakAok(bool b) {if(b){cout<<"Takahashi"<<'\n';} else{cout<<"Aoki"<<'\n';}} int GetTime() {return 1000.0*static_cast<double>(clock() - TIME_START) / CLOCKS_PER_SEC;} ll myRand(ll B) {return (unsigned long long)rng() % B;} template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } ll GCD(ll a, ll b) { if(a < b) swap(a, b); if(b == 0) return a; if(a%b == 0) return b; else return GCD(b, a%b); } ll LCM(ll a, ll b) { assert(GCD(a,b) != 0); return a / GCD(a, b) * b; } ll MOD(ll &x, const ll P) { ll ret = x%P; if(ret < 0) ret += P; return x = ret; } /// x % P を非負整数に直す ll mpow(ll x, ll n, const ll mod) { x %= mod; ll ret = 1; while(n > 0) { if(n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } /// x^n % mod を計算 ll lpow(ll x, ll n) { ll ret = 1; while(n > 0){ if(n & 1) ret = ret * x; x = x * x; n >>= 1; } return ret; } /// x^nを計算 string toBinary(ll n) { if(n == 0) return "0"; assert(n > 0); string ret; while (n != 0){ ret += ( (n & 1) == 1 ? '1' : '0' ); n >>= 1; } reverse(ret.begin(), ret.end()); return ret; } /// 10進数(long long) -> 2進数(string)への変換 ll toDecimal(string S) { ll ret = 0; for(int i = 0; i < (int)S.size(); i++){ ret *= 2LL; if(S[i] == '1') ret += 1; } return ret; } /// 2進数(string) → 10進数(long long)への変換 int ceil_pow2(ll n) { int x = 0; while ((1ll << x) < n) x++; return x;} /// return minimum non-negative `x` s.t. `n <= 2**x` int floor_pow2(ll n) { int x = 0; while ((1ll << (x+1)) <= n) x++; return x;} /// return maximum non-negative `x` s.t. `n >= 2**x` // ############################ // # # // # C O D E S T A R T # // # # // ############################ void solve() { debug(ceil_pow2(3)); debug(ceil_pow2(4)); debug(ceil_pow2(5)); debug(floor_pow2(3),floor_pow2(4),floor_pow2(5)); debuga; assert(true); Case(0); debugnl; ll N,M; cin >> N >> M; vll L(N); rep(i,N) cin >> L[i]; vll F(M); vll B(M); vll W(M); rep(i,M) cin >> F[i] >> B[i] >> W[i]; ll ans = 0; rep(i,M) { auto it = lower_bound(all(L), F[i]); ll cand1 = INFL; if(it != L.end()) cand1 = *it; ll cand2 = -INFL; if(it != L.begin()) { it--; cand2 = *it; } ans += max(B[i], W[i] - min(abs(F[i]-cand1), abs(F[i]-cand2))); } cout << ans << nl; } signed main() { cin.tie(0); ios_base::sync_with_stdio(false); TIMER_START; //cout << fixed << setprecision(15); int tt = 1; //cin >> tt; while(tt--){ solve(); } TIMECHECK; return 0; }