結果
問題 | No.2319 Friends+ |
ユーザー | Jerry Li |
提出日時 | 2023-12-25 17:09:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,902 bytes |
コンパイル時間 | 2,487 ms |
コンパイル使用メモリ | 226,344 KB |
実行使用メモリ | 88,976 KB |
最終ジャッジ日時 | 2024-09-27 14:31:42 |
合計ジャッジ時間 | 9,387 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
52,476 KB |
testcase_01 | AC | 15 ms
52,400 KB |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | AC | 2,704 ms
83,940 KB |
testcase_05 | AC | 2,954 ms
84,064 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 430 ms
88,872 KB |
testcase_08 | AC | 432 ms
88,972 KB |
testcase_09 | AC | 451 ms
88,972 KB |
testcase_10 | AC | 452 ms
88,856 KB |
testcase_11 | AC | 439 ms
88,976 KB |
testcase_12 | AC | 15 ms
52,412 KB |
testcase_13 | AC | 16 ms
52,708 KB |
testcase_14 | WA | - |
testcase_15 | AC | 17 ms
52,632 KB |
testcase_16 | WA | - |
testcase_17 | AC | 15 ms
52,572 KB |
testcase_18 | AC | 194 ms
65,532 KB |
testcase_19 | AC | 2,477 ms
83,676 KB |
testcase_20 | AC | 322 ms
77,684 KB |
testcase_21 | AC | 293 ms
75,840 KB |
testcase_22 | AC | 373 ms
83,648 KB |
testcase_23 | AC | 1,581 ms
83,520 KB |
testcase_24 | AC | 984 ms
83,804 KB |
testcase_25 | AC | 716 ms
83,888 KB |
testcase_26 | AC | 605 ms
83,712 KB |
testcase_27 | AC | 516 ms
83,648 KB |
testcase_28 | AC | 407 ms
83,784 KB |
testcase_29 | AC | 378 ms
83,704 KB |
testcase_30 | AC | 369 ms
83,740 KB |
testcase_31 | AC | 309 ms
77,248 KB |
testcase_32 | AC | 287 ms
75,332 KB |
testcase_33 | AC | 266 ms
71,328 KB |
testcase_34 | AC | 240 ms
69,040 KB |
testcase_35 | AC | 239 ms
67,116 KB |
testcase_36 | AC | 898 ms
84,148 KB |
testcase_37 | AC | 290 ms
83,524 KB |
testcase_38 | AC | 377 ms
83,828 KB |
testcase_39 | AC | 360 ms
83,740 KB |
testcase_40 | AC | 392 ms
83,868 KB |
testcase_41 | AC | 356 ms
83,592 KB |
testcase_42 | AC | 371 ms
83,684 KB |
testcase_43 | AC | 347 ms
83,712 KB |
testcase_44 | AC | 368 ms
83,820 KB |
testcase_45 | AC | 414 ms
84,568 KB |
testcase_46 | AC | 524 ms
83,208 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long typedef int uci; #define int long long #define F first #define S second typedef complex<double> cd; seed_seq seq{ (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(), (uint64_t) __builtin_ia32_rdtsc(), (uint64_t) (uintptr_t) make_unique<char>().get() }; mt19937 rng(seq); mt19937_64 lrng(seq); struct debugger{ template <typename T> debugger& operator<<(T &a){ #ifdef DEBUG cerr << a; #endif return *this; } template <typename T> debugger& operator<<(T &&a){ #ifdef DEBUG cerr << a; #endif return *this; } } deb; const double PI = acos(-1.0); const int MAX_N = 1e5 + 1; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; //! function insert //THINK FIRST, CODE SECOND //DON'T GET STUCK ON ONE STRATEGY //CALM DOWNNN FOR ONCE IN YOUR LIFE //REDUCE //COUGH E??!?!?!! O.O //uwu i see you ryan int adj[20000][313]; void solve() { memset(adj, 0, sizeof(adj)); int n, m; cin >> n >> m; vector<ar<int, 2>> edges(m); vector<int> curr(n); for(int i{}; i < n; ++i) cin >> curr[i]; vector<int> place(n); for(int i{}; i < n; ++i) place[i] = i/64; vector<int> bits(n); for(int i{}; i < n; ++i) bits[i] = (1<<i%64); vector<vector<int>> a(n); for(int i{}; i < m; ++i){ cin >> edges[i][0] >> edges[i][1]; edges[i][0]--, edges[i][1]--; adj[edges[i][0]][place[edges[i][1]]] |= bits[edges[i][1]]; adj[edges[i][1]][place[edges[i][0]]] |= bits[edges[i][0]]; a[edges[i][0]].push_back(edges[i][1]); a[edges[i][1]].push_back(edges[i][0]); } int q; cin >> q; vector<ar<int, 2>> qs(q); for(int i{}; i < q; ++i){ cin >> qs[i][0] >> qs[i][1]; qs[i][0]--, qs[i][1]--; } int sq = sqrt(q); vector<int> from_room(sq); vector<int> to_room(sq); string out(q, '0'); unordered_map<int, int> counts; for(int j{}; j < m; ++j){ counts[(edges[j][0]<<16)|curr[edges[j][1]]]++; counts[(edges[j][1]<<16)|curr[edges[j][0]]]++; } vector<int> orig_room(curr); for(int i{}; i < q; i += sq){ int last = min(q, i+sq); for(int j = i; j < last; ++j){ int f_room = curr[qs[j][0]]; int t_room = curr[qs[j][1]]; if(f_room == t_room) continue; int st = counts[(qs[j][0]<<16)|t_room]; for(int k = i; k < j; ++k){ if(out[k] == '1' && ((adj[qs[j][0]][place[qs[k][0]]])&(bits[qs[k][0]]))){ if(from_room[k-i] == t_room) st--; else if(to_room[k-i] == t_room) st++; } } if(st > 0){ out[j] = '1'; from_room[j-i] = f_room; to_room[j-i] = t_room; curr[qs[j][0]] = t_room; } } for(int j{}; j < n; ++j){ if(orig_room[j] != curr[j]){ for(int k : a[j]){ counts[(k<<16)|orig_room[j]]--; if(counts[(k<<16)|orig_room[j]] == 0) counts.erase((k<<16)|orig_room[j]); counts[(k<<16)|curr[j]]++; } } orig_room[j] = curr[j]; } } for(int i{}; i < q; ++i){ if(out[i] == '0') cout << "No\n"; else cout << "Yes\n"; } } uci main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // cout << "Case #" << t << ": "; solve(); } /* random number generator stuff num = rng(); gives integer number num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b] num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b) can also instantiate distributions and call on generator: uniform_int_distribution<int> thing(a, b); num = thing(rng); */ // struct custom_hash { // static uint64_t splitmix64(uint64_t x) { // // http://xorshift.di.unimi.it/splitmix64.c // 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 = lrng(); // return splitmix64(x + FIXED_RANDOM); // } // };