Asa's CP Library

a01sa01to's competitive programming library.

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub a01sa01to/cp-library

:heavy_check_mark: Associative Array (連想配列)
(tests/stl/associative-array.test.cpp)

STL の map を使う

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#define PROBLEM "https://judge.yosupo.jp/problem/associative_array"

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int q;
  cin >> q;
  map<ll, ll> mp;
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      ll k, v;
      cin >> k >> v;
      mp[k] = v;
    }
    else {
      ll k;
      cin >> k;
      cout << mp[k] << '\n';
    }
  }
  return 0;
}
#line 1 "tests/stl/associative-array.test.cpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#define PROBLEM "https://judge.yosupo.jp/problem/associative_array"

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int q;
  cin >> q;
  map<ll, ll> mp;
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      ll k, v;
      cin >> k >> v;
      mp[k] = v;
    }
    else {
      ll k;
      cin >> k;
      cout << mp[k] << '\n';
    }
  }
  return 0;
}
Back to top page