結果
問題 | No.3025 Chocol∀te |
ユーザー |
👑 |
提出日時 | 2025-02-14 22:06:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 524 ms / 2,000 ms |
コード長 | 3,184 bytes |
コンパイル時間 | 1,507 ms |
コンパイル使用メモリ | 122,816 KB |
実行使用メモリ | 22,412 KB |
最終ジャッジ日時 | 2025-02-14 22:10:08 |
合計ジャッジ時間 | 16,964 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 77 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:66:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | scanf("%d%d", &X[m], &Y[m]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:72:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | scanf("%lld", &A[u]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:74:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 74 | scanf("%d", &Q); | ~~~~~^~~~~~~~~~ main.cpp:80:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 80 | scanf("%d", &O[q]); | ~~~~~^~~~~~~~~~~~~ main.cpp:82:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 82 | scanf("%d%d", &U[q], &V[q]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:86:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | scanf("%d%lld", &U[q], &B[q]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:89:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 89 | scanf("%d", &U[q]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cassert>#include <cmath>#include <cstdint>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <bitset>#include <complex>#include <deque>#include <functional>#include <iostream>#include <limits>#include <map>#include <numeric>#include <queue>#include <random>#include <set>#include <sstream>#include <string>#include <unordered_map>#include <unordered_set>#include <utility>#include <vector>using namespace std;using Int = long long;template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i>= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }#define COLOR(s) ("\x1b[" s "m")int N, M;vector<int> X, Y;vector<Int> A;int Q;vector<int> O, U, V;vector<Int> B;vector<int> deg;vector<set<int>> graph;vector<Int> as, incoming;void flip(int u, int v) {if (make_pair(deg[u], u) > make_pair(deg[v], v)) swap(u, v);auto it = graph[u].find(v);if (it != graph[u].end()) {graph[u].erase(it);incoming[v] -= as[u];} else {graph[u].insert(v);incoming[v] += as[u];}}int main() {for (; ~scanf("%d%d", &N, &M); ) {X.resize(M);Y.resize(M);for (int m = 0; m < M; ++m) {scanf("%d%d", &X[m], &Y[m]);--X[m];--Y[m];}A.resize(N);for (int u = 0; u < N; ++u) {scanf("%lld", &A[u]);}scanf("%d", &Q);O.assign(Q, -1);U.assign(Q, -1);V.assign(Q, -1);B.assign(Q, -1);for (int q = 0; q < Q; ++q) {scanf("%d", &O[q]);if (O[q] == 1) {scanf("%d%d", &U[q], &V[q]);--U[q];--V[q];} else if (O[q] == 2) {scanf("%d%lld", &U[q], &B[q]);--U[q];} else if (O[q] == 3) {scanf("%d", &U[q]);--U[q];} else {assert(false);}}deg.assign(N, 0);for (int m = 0; m < M; ++m) {++deg[X[m]];++deg[Y[m]];}for (int q = 0; q < Q; ++q) if (O[q] == 1) {++deg[U[q]];++deg[V[q]];}graph.assign(N, {});as = A;incoming.assign(N, 0);for (int m = 0; m < M; ++m) {flip(X[m], Y[m]);}for (int q = 0; q < Q; ++q) {if (O[q] == 1) {flip(U[q], V[q]);} else if (O[q] == 2) {const Int diff = B[q] - as[U[q]];as[U[q]] = B[q];for (const int v : graph[U[q]]) incoming[v] += diff;} else if (O[q] == 3) {Int ans = incoming[U[q]];for (const int v : graph[U[q]]) ans += as[v];printf("%lld\n", ans);} else {assert(false);}}}return 0;}