a01sa01to's competitive programming library.
STL の map
を使う
#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;
}