# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
159427 |
2019-10-22T16:55:59 Z |
AM1648 |
Plahte (COCI17_plahte) |
C++17 |
|
279 ms |
36476 KB |
/* be name khoda */
// #define stream_enable
// #define long_enable
#define debug_enable
#include <iostream>
#include <map>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <queue>
#include <stack>
#include <limits.h>
#include <fstream>
#include <cstring>
using namespace std;
#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif
typedef long double dbl;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
const ll MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
#ifdef long_enable
const ll INF = LONG_LONG_MAX;
#else
const ll INF = INT_MAX;
#endif
const ll adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const ll adj8[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define print4(x, y, z, t) cout << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << '\n'
#define printp(x) cout << "(" << (x).ff << ", " << (x).ss << ")" << '\n'
#define printa(x, n) fori (ja12345, n) { cout << (x)[ja12345] << ' '; } cout << '\n'
#define printap(x, n) fori (ia1234567, n) { cout << "(" << (x)[ia1234567].ff << ", " << (x)[ia1234567].ss << ")" << '\n'; }
#define printaa(x, n, m) fori (iaa123456, n) { fori (jaa123456, m) { cout << (x)[iaa123456][jaa123456] << ' '; } cout << '\n'; }
#define printav(x, n) fori (iaa123477, n) { printv((x)[iaa123477]); }
#define printia(x, n) fori (ja212345, n) { cout << ja212345 << " : " << (x)[ja212345] << '\n'; }
#ifdef debug_enable
#define debug(x) cout << #x << " -> "; print(x)
#define debug2(x, y) cout << #x << ' ' << #y << " -> "; print2(x, y)
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> "; print3(x, y, z)
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> "; print4(x, y, z, t)
#define debugp(x) cout << #x << " -> "; printp(x)
#define debuga(x, n) cout << #x << " -> "; printa(x, n)
#define debugap(x, n) cout << #x << " ->\n"; printap(x, n)
#define debugaa(x, n, m) cout << #x << " ->\n"; printaa(x, n, m)
#define debugav(x, n) cout << #x << " ->\n"; printav(x, n)
#define debugia(x, n) cout << #x << " ->\n"; printia(x, n)
#else
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x, y, z, t)
#define debugp(x)
#define debuga(x, n)
#define debugap(x, n)
#define debugaa(x, n, m)
#define debugav(x, n, m)
#define debugia(x, n)
#endif
#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))
#define inp(x) ll x; cin >> x
#define inp2(x, y) ll x, y; cin >> x >> y
#define inp3(x, y, z) ll x, y, z; cin >> x >> y >> z
#define inp4(x, y, z, w) ll x, y, z, w; cin >> x >> y >> z >> w
#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll powMod(ll a, ll b) {
ll n = 1;
ll p = a;
while (b > 0) {
if (b % 2 == 1) {
n *= p;
n %= MOD;
}
p *= p;
p %= MOD;
b /= 2;
}
return n;
}
ll modularInverse(ll a) {
return powMod(a, MOD - 2);
}
stringstream sss;
// -----------------------------------------------------------------------
const ll maxn = 80010;
const ll maxI = maxn * 2;
ll N;
ll par[maxn];
array<ll, 5> irects[maxn];
array<ll, 3> ipts[maxn];
vector<array<ll, 3>> rects[maxI];
vector<array<ll, 2>> pts[maxI];
vi compx, compy;
ll seg[maxI * 4], lazy[maxI * 4];
vi subt[maxn];
set<ll> cols[maxn];
ll rt[maxn];
ll ans[maxn];
void push(ll x) {
seg[x * 2] = lazy[x * 2] = lazy[x];
seg[x * 2 + 1] = lazy[x * 2 + 1] = lazy[x];
lazy[x] = -1;
}
void update(ll li, ll ri, ll v, ll x = 1, ll l = 0, ll r = N) {
if (li >= r || l >= ri) {
} else if (li <= l && r <= ri) {
seg[x] = lazy[x] = v;
} else {
if (lazy[x] != -1) {
push(x);
}
ll mid = (l + r) / 2;
update(li, ri, v, x * 2, l, mid);
update(li, ri, v, x * 2 + 1, mid, r);
}
}
ll get(ll pos, ll x = 1, ll l = 0, ll r = N) {
if (r - l == 1) {
return seg[x];
} else {
if (lazy[x] != -1) {
push(x);
}
ll mid = (l + r) / 2;
if (pos < mid) {
return get(pos, x * 2, l, mid);
} else {
return get(pos, x * 2 + 1, mid, r);
}
}
}
void dfs(ll x, ll par) {
ll mx = x;
for (auto y : subt[x]) {
dfs(y, x);
if (cols[rt[y]].size() > cols[mx].size()) {
mx = rt[y];
}
}
rt[x] = mx;
if (mx != x) {
for (auto c : cols[x]) {
cols[mx].insert(c);
}
}
for (auto y : subt[x]) {
if (rt[y] == mx) continue;
for (auto c : cols[rt[y]]) {
cols[mx].insert(c);
}
}
ans[x] = cols[mx].size();
}
void MAIN() {
ll n, m;
cin >> n >> m;
fori (i, n) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
++c;
++d;
compx.pb(a);
compx.pb(c);
compy.pb(b);
compy.pb(d);
irects[i] = {a, b, c, d, i + 1};
}
fori (i, m) {
ll x, y, k;
cin >> x >> y >> k;
compx.pb(x);
compy.pb(y);
ipts[i] = {x, y, k};
}
sort(all(compx));
compx.resize(unique(all(compx)) - compx.begin());
sort(all(compy));
compy.resize(unique(all(compy)) - compy.begin());
N = compy.size();
ll nn = compx.size();
fori (i, n) {
ll a = lower_bound(all(compx), irects[i][0]) - compx.begin();
ll b = lower_bound(all(compy), irects[i][1]) - compy.begin();
ll c = lower_bound(all(compx), irects[i][2]) - compx.begin();
ll d = lower_bound(all(compy), irects[i][3]) - compy.begin();
rects[a].pb({b, d, irects[i][4]});
rects[c].pb({b, d, -irects[i][4]});
}
fori (i, m) {
ll x = lower_bound(all(compx), ipts[i][0]) - compx.begin();
ll y = lower_bound(all(compy), ipts[i][1]) - compy.begin();
pts[x].pb({y, ipts[i][2]});
}
memset(lazy, -1, sizeof lazy);
fori (i, nn) {
for (auto inter : rects[i]) {
if (inter[2] > 0) {
par[inter[2]] = get(inter[0]);
subt[par[inter[2]]].pb(inter[2]);
update(inter[0], inter[1], inter[2]);
} else {
update(inter[0], inter[1], par[-inter[2]]);
}
}
for (auto pt : pts[i]) {
ll node = get(pt[0]);
cols[node].insert(pt[1]);
}
}
dfs(0, 0);
forifrom (i, 1, n + 1) {
print(ans[i]);
}
}
// -----------------------------------------------------------------------
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
sss << R"(
1 3
1 1 7 7
2 6 2
4 7 3
4 4 1
2 2
1 1 3 3
5 6 10 10
3 3 1
5 1 2
3 3
1 1 7 7
2 2 6 6
3 3 5 5
4 4 1
2 6 2
4 7 3
)";
MAIN();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
23788 KB |
Output is correct |
2 |
Correct |
136 ms |
25836 KB |
Output is correct |
3 |
Incorrect |
16 ms |
15992 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
25804 KB |
Output is correct |
2 |
Correct |
160 ms |
26604 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
33824 KB |
Output is correct |
2 |
Correct |
275 ms |
32192 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
158 ms |
36448 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
160 ms |
36476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |