Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '#include <iostream>
- #include <algorithm>
- #include <set>
- #include <queue>
- #include <vector>
- using namespace std;
- struct LastElementLess {
- bool operator()(const std::multiset<int> &first, const std::multiset<int> &second) const {
- if (second.empty()) {
- return false;
- }
- if (first.empty()) {
- return true;
- }
- return *first.rbegin() < *second.rbegin();
- }
- };
- int fasti() {
- char c = ' '; int a = 0;
- while (!isdigit(c)) c = _getchar_nolock();
- while (isdigit(c)) {
- a = a * 10 + c - '0';
- c = _getchar_nolock();
- }
- return a;
- }
- int main() {
- int n, m, l, r, q, k, s, ans, pr;
- cin >> n >> m >> q >> k;
- vector<vector<int>> a(n, vector<int>(m));
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++)
- a[i][j] = fasti();
- }
- multiset< multiset <int>, LastElementLess > g;
- for (int i = 0; i < n; i++) {
- multiset<int> pr1;
- for (int j = 0; j < m; j++) {
- pr1.insert(a[i][j]);
- }
- g.insert(pr1);
- }
- for (int i = 0; i < m; i++) {
- multiset<int> pr1;
- for (int j = 0; j < n; j++) {
- pr1.insert(a[j][i]);
- }
- g.insert(pr1);
- }
- /*for (auto rl : g) {
- for (auto el : rl) {
- cout << el << ' ';
- }
- cout << 'n';
- }*/
- for (int i = 0; i < q; i++) {
- l = fasti(); r = fasti(); l--; r--;
- s = a[l][r];
- for (auto el = g.begin(); el != g.end(); el++) {
- auto it = (*el).find(s);
- if (it != (*el).end()) {
- if ((*el).size() == 1)
- (*el).insert(0); // тут
- (*el).erase(it); // и тут ошибка хз почему
- break;
- }
- }
- auto it = g.begin();
- auto it1 = (*it).end();
- it1--;
- cout << *it1 << 'n';
- }
- }'
Add Comment
Please, Sign In to add comment