Submission #14715538
Source Code Expand
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on
const int N = 200002;
int main() {
int n, q;
scanf(" %d %d", &n, &q);
vector<multiset<int>> s(N);
multiset<int> mx;
vector<int> a(n), b(n);
rep(i, n) {
scanf(" %d %d", &a[i], &b[i]);
s[b[i]].insert(a[i]);
}
rep(i, N) if (!s[i].empty()) mx.insert(*(s[i].rbegin()));
auto F = [&](int idx, int to) {
int rate = a[idx];
int from = b[idx];
for (int i : {from, to}) {
if (!s[i].empty()) mx.erase(mx.find(*(s[i].rbegin())));
}
s[from].erase(s[from].find(rate));
s[to].insert(rate);
for (int i : {from, to}) {
if (!s[i].empty()) mx.insert(*(s[i].rbegin()));
}
b[idx] = to;
return *(mx.begin());
};
rep(i, q) {
int c, d;
scanf(" %d %d", &c, &d);
--c;
printf("%d\n", F(c, d));
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Smart Infants |
| User |
imulan |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
1476 Byte |
| Status |
AC |
| Exec Time |
580 ms |
| Memory |
29712 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:19:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
19 | scanf(" %d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~
./Main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
26 | scanf(" %d %d", &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
./Main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
53 | scanf(" %d %d", &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
AC
|
|
| Set Name |
Test Cases |
| Sample |
|
| All |
handmade02, handmade03, handmade04, handmade05, handmade06, handmade07, handmade08, handmade09, random10, sample00, sample01 |
| Case Name |
Status |
Exec Time |
Memory |
| handmade02 |
AC |
14 ms |
12660 KiB |
| handmade03 |
AC |
16 ms |
12584 KiB |
| handmade04 |
AC |
16 ms |
12600 KiB |
| handmade05 |
AC |
96 ms |
12772 KiB |
| handmade06 |
AC |
371 ms |
23356 KiB |
| handmade07 |
AC |
385 ms |
23484 KiB |
| handmade08 |
AC |
270 ms |
29712 KiB |
| handmade09 |
AC |
279 ms |
29596 KiB |
| random10 |
AC |
580 ms |
29616 KiB |
| sample00 |
AC |
16 ms |
12600 KiB |
| sample01 |
AC |
12 ms |
12652 KiB |