# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42796 | funcsr | Aliens (IOI16_aliens) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define INF 1145141919
#define _1 first
#define _2 second
long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) {
vector<P> ps;
rep(i, N) {
int l = R[i], r = C[i];
if (l > r) swap(l, r);
ps.pb(P(l, -r));
}
sort(all(ps));
int r = -1;
vector<P> nps;
for (P p : ps) {
if (-p._2 > r) {
nps.pb(P(p._1, -p._2));
r = -p._2;
}
}
swap(ps, nps);
int last_r = -1;
long long s = 0;
assert(K==N);
for (P p : ps) {
int l = p._1, r = p._2;
//cout<<"["<<l<<","<<r<<"]\n";
s += 1LL*(r-l+1)*(r-l+1);
if (l <= last_r) s -= 1LL*(last_r-l+1)*(last_r-l+1);
last_r = r;
}
return s;
}