Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 1000000009) x -= 1000000009; if (x < 0) x += 1000000009; return x; } long long mul(long long a, long long b) { return (a * b) % 1000000009; } long long pw(long long a, long long b) { ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; map<pair<int, int>, int> mp; int x[100010]; int y[100010]; long long ans[100010]; bool unable[100010]; bool judge(int xx, int yy) { int ok = 1; if (mp.count(make_pair(xx, yy + 1))) { if (mp.count(make_pair(xx - 1, yy)) == 0 && ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.nio.ReadOnlyBufferException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashS...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; const int MAXN = 1000006; vector<int> ANS; pair<int, int> P[MAXN]; set<int> S; map<pair<int, int>, int> M; int numer(int a, int b) { typeof(M.begin()) it = M.find(pair<int, int>(a, b)); if (it == M.end()) return -1; return it->second; } int...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long mod = (long long)(1e9 + 7)) { if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 9; const int SIZE = 1e5 + 10; int x[SIZE], y[SIZE]; vector<int> e[SIZE], from[SIZE]; int sup[SIZE]; bool used[SIZE]; int an[SIZE]; set<int> can; bool test(int i) { if (used[i]) return 0; bool stop = 0; for (int j = 0; j < (((int)(e[i]).size())); ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; set<int> s; int x[200100], y[200100]; bool exist(int xx, int yy) { return mp.count(pair<int, int>(xx, yy)) && mp[pair<int, int>(xx, yy)] != -1; } bool check(int xx, int yy) { if (!exist(xx, yy)) return true; if (yy == 0) return true; if ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int m; long long base[300111]; const int dir[8][2] = {-1, -1, 0, -1, 1, -1, -1, 0, 1, 0, -1, 1, 0, 1, 1, 1}; struct _Node { long long value, x, y; bool operator<(const _Node &x) const { return value > x.value; } }; struct Node { long long value, x, y; bool operator<...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; long long mod = 1000000009; int main() { int num; scanf("%d", &num); set<pair<int, int> > se; map<pair<int, int>, int> ma; map<pair<int, int>, int> dat; for (int i = 0; i < num; i++) { int za, zb; scanf("%d%d", &za, &zb); se.insert(make_pair(za, zb))...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 9; int n; pair<int, int> p[100010]; map<pair<int, int>, int> mymap; bool check(pair<int, int> buf) { if (mymap[buf] == 0) return false; int x = buf.first; int y = buf.second; for (int i = -1; i <= 1; i++) { int nx = x + i; int ny =...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.PriorityQueue; import ...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int dx[3] = {-1, 0, 1}; const int dy[3] = {-1, -1, -1}; const int INF = 1e9 + 9; int n; int x[maxn], y[maxn], cnt[maxn]; map<pair<int, int>, int> id; set<int> s; inline void upd(int i, int d) { if (!cnt[i]) s.erase(i); cnt[i] += d; if (...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; map<pair<long long int, long long int>, long long int> indexes; vector<long long int> nb_below; bool can_remove(const pair<long long int, long long int> c) { auto it = indexes.find(make_pair(c.first, c.second + 1)); if (it != indexes.end() && nb_below[it->second] == 1) ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; const long long Mod = 1000000009; int m; map<pair<int, int>, int> Td; set<int> p; int vis[maxn]; int xi[maxn], yi[maxn]; bool check(int t) { int x = xi[t], y = yi[t]; if (Td.count({x - 1, y + 1})) { int w = Td[{x - 1, y + 1}]; if (vis[w]...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, int> m; pair<long long, long long> pos[112345]; set<int> down[112345]; set<int> up[112345]; int dx[] = {-1, 0, 1}; bool puedosacar(int i) { for (auto x : up[i]) if (down[x].size() == 1) return false; return true; } int main() { ios:...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int mod = 1e9 + 9; struct Node { int x, y; Node() {} Node(int x, int y) : x(x), y(y) {} bool operator<(const Node& a) const { if (x != a.x) return x < a.x; return y < a.y; } }; int n; Node a[MAXN]; int vis[MAXN]; map<Node, in...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50, mod = 1e9 + 9; int n, vis[maxn], in[maxn], ans[maxn]; struct node { pair<int, int> p; int id; node() {} node(pair<int, int> p1, int i1) : p(p1), id(i1) {} }; map<pair<int, int>, int> mp; vector<int> v1[maxn], v2[maxn]; void Debug() { cou...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MOD = 1e9 + 9; long long sup[MAXN]; long long x[MAXN], y[MAXN], del[MAXN]; map<pair<long long, long long>, int> mp; int be_supported(long long x, long long y) { int cnt = 0; for (int j = -1; j < 2; j++) { long long nx = x + j, ny...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct Cube { long x, y; long countDependOnHim; }; int main() { long m; cin >> m; vector<Cube> cubes; map<pair<long, long>, long> cubeToId; for (long i = 0; i < m; i++) { long x, y; cin >> x >> y; cubeToId[make_pair(x, y)] = i; Cube newCube; ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; long n, x[1 << 20], y[1 << 20]; set<pair<long, long> > have; map<pair<long, long>, long> mapp; pair<long, long> tp; long mark[1 << 20]; long stand[1 << 20]; long bad[1 << 20]; set<long> nice; set<long>::iterator it; long long ans; long crits[1 << 20]; void reeval(pair<long,...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
from sys import stdin from heapq import heappop, heappush from collections import defaultdict def main(): n = int(stdin.readline()) a = [tuple(map(int, stdin.readline().split())) for _ in xrange(n)] d = defaultdict(int) for i, x in enumerate(a): d[x] = i b = [0] * n for i, t in enumerate...
PYTHON
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.util.NavigableSet; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.Iterator; import java.io.IOException; import java....
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000009; const int maxn = 100005; typedef struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} friend bool operator<(Point a, Point b) { return a.x != b.x ? a.x < b.x : a.y < b.y; } } Point; map<Point, int> mp; map<Point,...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 9; int add(long long int x, long long int y) { return (x + y) % mod; } int mul(long long int x, long long int y) { return (x * y) % mod; } int n; pair<int, int> a[112345]; map<pair<int, int>, int> b; map<pair<int, int>, int>::iterator bi; map...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.awt.geom.Point2D; import java.math.BigInteger; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static int m; static Map<Point2D,Integer> cubesInF...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; int n, x[100005], y[100005], pw[100005]; set<pair<int, int> > alls; set<int> cannow; map<pair<int, int>, int> mp; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); alls.insert(make_pair(x[i], y[i...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.*; import java.util.*; /** * @author master_j * @version 0.4.1 * @since Mar 22, 2015 */ public class Solution { int n; Pair[] indPairMap; Map<Pair, Integer> pairIntMap = new TreeMap<>(); int[] childrenSizes; int[] parentsSizes; int[][] parents; int[][] children; priv...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; long long ans; int m, n, x[100009], y[100009]; map<pair<int, int>, int> f; set<int> s; bool chk(int x, int y) { for (int i = -1; i <= 1; ++i) if (f.find(make_pair(x + i, y + 1)) != f.end()) { int j; for (j = -1; j <= 1; ++j) { ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 9; void MAIN(); int main() { MAIN(); return 0; } const int N = (int)1e5 + 32; int n, used[N]; map<pair<int, int>, int> mp; set<int> fre; pair<int, int> x[N]; int pos(int a, int b) { if (mp.find(pair<int, int>(a, b)) == mp.end()) return -1; ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128777216") using namespace std; const long long LINF = 1000000000000000000LL; const int INF = 1000000000; const long double eps = 1e-9; const long double PI = 3.1415926535897932384626433832795l; void prepare(string s) { if (s.length() != 0) { freopen((s + ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long bp = 1e9 + 9; map<pair<int, int>, int> Map; map<int, int> Mapx; set<long long> Set; int df[] = {-1, 0, 1}; int x[N], y[N]; long long ans; inline int cp(const int &px, const int &py) { if (!Map.count(pair<int, int>(px, py))) return -...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100500; const int INF = 1000000000, mod = 1000000009; const long long LLINF = 1000000000000000000ll; struct cube { int x, y, c; cube() {} cube(int x, int y, int c) : x(x), y(y), c(c) {} bool operator<(const cube &a) const { return c < a.c; } }; vector<...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int n; int x[100005], y[100005]; map<pair<int, int>, int> mp; int r[100005]; set<int> s; int ans[100005]; int vis[100005]; long long mod2 = 1000000009; int ok(int i) { int nx, ny, te; nx = x[i] - 1; ny = y[i] + 1; te = mp[make_pair(nx, ny)]; if (te != 0 && r[te - ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int x[102400], y[102400]; map<pair<int, int>, int> id; bool no[102400]; set<int> u[102400], v[102400]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", x + i, y + i); id[{x[i], y[i]}] = i; } for (int i = 0; i < n; ++i) f...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int MODP(long long x) { int r = x % 1000000009; if (r < 0) r += 1000000009; return r; } void testGen() { freopen("biginput1.txt", "w", stdout); fclose(stdout); } class DirectedGraph { vector<vector<int>> nodeFrom; vector<vector<int>> nodeTo; vector<int> degI...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int n, x[100009], y[100009], bit[131077], power[100009], mod = 1000000009; bool used[100009], u2[100009]; vector<tuple<int, int, int>> Z; vector<int> fd[100009], fu[100009]; void add(int pos, int x) { x += 0; while (pos <= 131072) { bit[pos] += x; pos += (pos & ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; const int mmax = 1e5 + 10; struct CUBE { int x, y, num; }; int m; CUBE cube[mmax]; map<pair<int, int>, int> ok; set<int> cando; int vis[mmax], tot; bool judge(int upx, int upy, int downx, int downy) { if (!ok[pair<int, int>(upx, upy)]) ret...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mmod = 1000000009; struct xyn { int x, y, num; xyn() {} xyn(int _x, int _y, int _num) { x = _x; y = _y; num = _num; } bool operator<(const xyn& another) const { if (x != another.x) return x < another.x; if (y != another.y) return y < ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MaxN = 2e5, pt = 1e9 + 9; int n; bool taken[MaxN + 5]; map<pair<int, int>, int> reloc; set<int> stsmall; set<int> stbig; struct LOC { int x, y; } loc[MaxN + 5]; struct ARR { int cnt; bool c[5]; } a[MaxN + 5]; bool cantake(int x) { for (int i = -1; i <= 1; ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.*; import java.util.*; public class Main extends PrintWriter { BufferedReader br; StringTokenizer stok; final Random rand = new Random(31); final int inf = (int) 1e9; final long linf = (long) 1e18; final int mod = inf + 7; class Cube { int x, y; int v; ...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Bit...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MaxN = 100000 + 10; struct Datas { int id, val; bool operator<(const Datas &b) const { return val > b.val; } }; struct Datab { int id, val; bool operator<(const Datab &b) const { return val < b.val; } }; priority_queue<Datas> qs; priority_queue<Datab> qb; ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 20), dx[3] = {1, 0, -1}, MOD = 1000000009; map<pair<int, int>, int> idx; int n; set<int> nxtv[MX], prevv[MX], S; void construct_edges() { for (auto it : idx) { int x = it.first.first, y = it.first.second, Idx = it.second, nx, ny, nIdx; for (in...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct _ { ios_base::Init i; _() { cin.sync_with_stdio(1); cin.tie(0); } } _; vector<int> adj[100100]; int dx[3] = {-1, 0, 1}; int dy[3] = {-1, -1, -1}; vector<int> par[100100]; vector<int> child[100100]; bool killed[100100]; map<pair<int, int>, int> R; bool c...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import heapq def coor_neighbor(coor, dxs, dys): x, y = coor for dx in dxs: for dy in dys: yield x + dx, y + dy def coor_bottoms(coor): return coor_neighbor(coor, (-1, 0, 1), (-1, )) def coor_tops(coor): return coor_neighbor(coor, (-1, 0, 1), (1, )) def coor_sibs(coor): ret...
PYTHON3
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> Map; set<pair<int, pair<int, int>>> Set; vector<pair<int, int>> base; bool if_removed(int x, int y) { if (Map[{x, y + 1}] != 0) { if (Map[{x - 1, y}] == 0 and Map[{x + 1, y}] == 0) { return false; } } if (Map[{x - 1, y + 1}] != 0...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct cube { int x, y; bool taken = false; bool takeable; }; int m; cube cs[100111]; map<pair<int, int>, int> fig; long long res; priority_queue<int> player1; priority_queue<int, vector<int>, greater<int> > player2; void check(int x, int y) { if (fig.count(make_pai...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int n; int x[100005], y[100005]; map<pair<int, int>, int> f; set<int> g; long long ans; bool yes(int tmp) { int ix, iy; ix = x[tmp] + 1; iy = y[tmp] + 1; if (f.count((make_pair(ix, iy)))) { if (!f.count((make_pair(ix, iy - 1))) && !f.count((make_pair(ix ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; const long long MOD = 1000000009; const int MAXM = 100010; int m; long long pow_mod[MAXM]; int X[MAXM], Y[MAXM]; map<pair<int, int>, int> ma; set<int> S; set<int> up[MAXM], down[MAXM]; void init() { pow_mod[0...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.Map.Entry; import static java.lang.Math.*; public class B extends PrintWriter { long point(long x, long y) { return (x << 32) | (y); } boolean isStabel(int x, int y, Map<Long, Integer> p, int rx, int ry) { if (y == 0 || !p.co...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); pair<int, int> toPoint[100011]; map<pair<int, int>, int> toIndex; int N, lo[100011]; bool check(pair<int, int> a) { if (!toIndex[a]) return false; for (int dx = -1; dx <= 1; dx++) { pair<int, int> n(a.first + dx, a.second + 1); int ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int ch_top = 1e7; char ch[ch_top], *now_r = ch - 1, *now_w = ch - 1; int read() { while (*++now_r < '-') ; if (*now_r == '-') { int x = *++now_r - '0'; while (*++now_r >= '0') x = x * 10 + *now_r - '0'; return -x; } int x = *now_r - '0'; whil...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int m; struct lel { int x, y, i; }; struct cmp2 { bool operator()(int a, int b) { return a > b; } }; bool cmp(lel a, lel b) { if (a.y == b.y) return a.x < b.x; return a.y > b.y; } lel t[100007]; vector<int> nati[100007]; vector<int> par[100007]; int in[100007]; long...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; int m; map<pair<int, int>, int> cubes; int x[100001], y[100001]; bool del[100001]; bool critical(int index) { for (int px = x[index] - 1; px <= x[index] + 1; px++) { int py = y[index] + 1; int p = cubes[make_pair(px, py)] - 1; if (p >=...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long delt = 1e9 + 9; long long ans; set<pair<int, int> > points; set<long long> rmv; map<pair<long long, long long>, long long> pnt; map<long long, pair<int, int> > ppnt; int n; int dir[10][2] = {{-1, 1}, {0, 1}, {1, 1}, {-1, -1}, {0, -1}, {1, ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; int n; int x[100000 + 20], y[100000 + 20]; vector<int> under[100000 + 20]; vector<int> above[100000 + 20]; set<int> can_take; set<int>::iterator it; int pw[100000 + 20]; int mod = 1000000009; int ans = 0; void read() { scanf("%d", &n); for (...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n; struct point { int x,...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.OutputStream; import java.util.Iterator; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; import java.util.TreeSet; import java.io.In...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; template <class T> inline void check_max(T& actual, T check) { if (actual < check) { actual = check; } } template <class T> inline void check_min(T& actual, T check) { if (actual > check) { actual = check; } } const double EPS = 1e-9; const int IINF = 100000...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100001, MOD = 1e9 + 9; int n; set<pair<int, int> > s; set<pair<int, pair<int, int> > > a; map<pair<int, int>, int> m; int mul(int a, int b) { return (int)(((long long)a * (long long)b) % MOD); } int binPow(int b, int p) { if (p == 0) return 1; if (p == 1) ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.util.List; import java.io.IOException; import java.util.InputMismatchException; import java.util.ArrayList; import java.util.HashMap; import java.util.Comparator; import java.io.OutputStream; import java.io.PrintWriter; import java.util.TreeSet; import java.io.InputStream; /** * Built using CHelper plug-i...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; long long binpow(long long v, int p) { if (p == 0) return 1 % mod; if (p & 1) return (v * binpow(v, p - 1)) % mod; else { long long t = binpow(v, p / 2); return (t * t) % mod; } } bool good_cub(pair<int, pair<int, int> > cu...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostream& operator<<(ostream& out, cons...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int n; long long int ans = 0; struct Point { int x, y; Point() {} Point(int _x, int _y) : x(_x), y(_y) {} } points[110000]; bool operator<(Point a, Point b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } map<Point, long long int> mp; set<long long int> he...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.OutputStream; import java.util.Iterator; import java.io.PrintWriter; import java.io.Writer; import java.io.IOExc...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int x[100010], y[100010]; map<int, map<int, int> > indice; map<int, map<int, int> > existe; int m; int ent[100010]; int sai[100010]; int dx[3] = {-1, 0, 1}; int dy[3] = {-1, -1, -1}; int vis[100010]; struct ComparaMaior { bool operator()(int a, int b) { return a < b; } };...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int next() { int x; cin >> x; return x; } long long lnext() { long long x; cin >> x; return x; } int main() { cout.precision(20); ios_base::sync_with_stdio(false); int m = next(); vector<pair<int, int> > cor; for (int i = 0; i < m; i++) { int x = n...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; map<pair<int, int>, int> mp; pair<int, int> p[MAXN]; int a[MAXN]; set<int> st; set<int>::iterator it; int link[MAXN]; bool used[MAXN]; const int MOD = 1e9 + 9; int num[MAXN]; void check(int x, int y) { pair<int, int> p = make_pair(x, y); if (mp....
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; map<pair<int, int>, int> in, id; set<int> S; int X[100010], Y[100010]; bool check(pair<int, int> P) { int x = P.first, y = P.second + 1; for (int dx = x - 1; dx <= x + 1; dx++) { if (in.count(make_pair(dx, y)) && in[make_pair(dx, y)] == 1...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int INF = (-1u) / 2; const long long int INF2 = (-1ull) / 2; int a, b, i, c[101100], j, k, n, m, timer = 0, l, r, x, y; int t[511000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0; pair<int, int> p[100020]; map<pair<int, int>, int> mp; set<int> st; set<int>::iterator i...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } long long setBit0(long long...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; long long read() { char c = getchar(); if (c < '0' && c > '9' && c != '-') c = getchar(); long long f = 1, cnt = 0; if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') { cnt = cnt * 10 + int(c - '0'); c = getchar(); } return cnt * f; } co...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.Iterator; import java.io.IOExc...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Reader; import java.util.HashMap; import java.util.Map.Entry; import java.util.StringTokenizer; import java.util.TreeMap; publ...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int m, x[100010], y[100010]; struct node { int x, y; bool operator<(const node& rhs) const { return x < rhs.x || (x == rhs.x && y < rhs.y); } }; map<node, int> ms; set<int> ss; set<int>::iterator it; struct edge { int t, nxt; } e[100010 * 10], be[100010 * 10]; i...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct block; struct block2 { long long id; int x; int y; block2(long long I, int X, int Y) : id(I), x(X), y(Y) {} bool operator<(const block2& oth) const { return (id < oth.id); } operator block() const; }; struct block { long long id; int x; int y; blo...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; class P { public: int x, y; P() {} P(int xx, int yy) { x = xx; y = yy; } }; bool operator<(P a, P b) { return a.x != b.x ? a.x < b.x : a.y < b.y; } int N, D[100010], ret[100010]; P a[100010]; map<P, int> mp; set<int> st; vector<int> g[100010]; long long MOD...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class b { static long mod = (long)(1e9+9); public static void main(String[] args) throws IOException { input.init(System.in); int n = input.nextInt(); int[]...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] args) { Cubes c=new Cubes(); c.begin(); } } class Cubes { private int nCubes; private Map<String,Cube> cubesMap; private List<Cube> mCubes; private static BigInteger mod=new BigInteger("10000...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Cubes { private static final int[] dx = new int[]{ -1, 0, 1 }; private static final long MOD = 1000000009L; private static HashMap<Cube, Integer> cubeToValue; public static vo...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; set<int> q; int m; pair<int, int> dat[111111]; map<pair<int, int>, int> mp; const long long mof = 1e9 + 9; inline long long pow_mod(long long a, long long k, long long mo) { long long ans = 1; while (k) { if (k % 2) ans = ans * a % mo; a = a * a % mo; k >>= ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)(1e5) + 10; const int MOD = (int)(1e9) + 9; struct Point { Point() {} Point(int xx, int yy) : x(xx), y(yy) {} int x, y; bool operator<(const Point &a) const { if (a.y == y) return x < a.x; return y < a.y; } } point[MAX_N]; int n; map...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.SortedSet; import java.util.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.util.TreeSet; import java.util.ArrayList; import java.util.List; import ...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int n, a[1000005], b[1000005]; int xx[] = {-2, -1, 1, 2, -1, 0, 1}; int yy[] = {0, 0, 0, 0, -1, -1, -1}; long long ans = 0; map<pair<int, int>, int> h; set<int> s; vector<int> cvp; int ne(int x, int y) { if (h.count(make_pair(x, y))) return h[make_pair(x, y)]; return 0;...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; long long f[100010]; struct node { int x, y, t; node(int x, int y, int t) : x(x), y(y), t(t) {} bool operator<(const node& a) const { return x < a.x || (x == a.x && y < a.y); } }; set<node> s; struct cmp1 { bool operator()(const node& ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct block; struct block2 { long long id; int x; int y; block2(long long I, int X, int Y) : id(I), x(X), y(Y) {} bool operator<(const block2& oth) const { return (id < oth.id); } operator block() const; }; struct block { long long id; int x; int y; blo...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
//package codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Locale; import java.util...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; scanf("%d", &n); ; set<pair<int, pair<int, int> > > val; set<pair<int, pair<int, int> > >::iterator it1; map<pair<int, int>, int> m; map<pair<int, int>, int>::iterator it; for (i = 0; i < n; i++) { int x, y; scanf("%d%d",...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 9; const int maxn = 100100; struct BOX { int x, y, id; } box[maxn]; int n; map<pair<int, int>, int> mPI; set<pair<int, int> > Pt; set<int> St; bool isST(int id) { int x = box[id].x; int y = box[id].y; pair<int, int> tp; tp = make_pa...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const long long MOD = 1e9 + 9; int m, x[N], y[N], out[N], used[N]; map<pair<int, int>, int> mp; vector<int> g[N], rg[N]; long long p[N]; int main() { scanf("%d", &m); p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i - 1] * m % MOD; for (in...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; set<int> s; set<int>::iterator it; int n; long long ans = 0; map<pair<int, int>, int> mp; int x_[100010]; int y_[100010]; int b[100010]; void change(int x, int y) { if (b[mp[make_pair(x - 1, y + 1)]] == 1) { s.erase(mp[make_pair(x, y)]); return; } if (b[mp[mak...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long> vr[100005]; long long n, pp[100005], deg[100005], dpd[100005], visit[100005]; pair<long long, long long> pr[100005]; map<pair<long long, long long>, long long> mr; set<long long> sr; long long mark[10][10]; long long is_needed(pair<long long, long long> p)...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MOD = (int)1e9 + 9; int x[MAXN], y[MAXN]; int ans; struct node { int d; int x, y; node(int a, int b, int c) : d(a), x(b), y(c){}; bool operator<(const node& a) const { return d < a.d; } }; map<pair<int, int>, int> mp; map<pair<int,...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; struct Cube { set<int> predki; set<int> potomki; int value; int x; int y; Cube() {} Cube(int X, int Y, int Value) { x = X; y = Y; value = Value; } }; bool comp(const Cube& a, const Cube& b) { if (a.y < b.y) return true; if (a.y > b.y) return ...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Cubes { private static final long MOD = 1000000009L; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(Sy...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
import java.io.*; import java.util.*; public class BMain { String noResultMessage = "NoResult"; Parser in = new Parser(); PrintWriter out; long div = (long) (9 + 1e9); int m = in.nextInteger(); int[][]xy = in.nextIntegers(2, m); int [] x = xy[0]; int [] y = xy[1]; public static c...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; map<pair<int, int>, int> mapa; pair<int, int> arr[100005]; int indeg[100005], outdeg[100005]; bool gone[100005]; bool ok(int x) { bool yes = true; for (int dx = -1; dx <= 1; ++dx) { int nx = arr[x].first + dx; int ny = arr[x].second +...
CPP
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.awt.geom.Point2D; import java.math.BigInteger; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static int m; static Map<Point2D,Integer> cubesInF...
JAVA
521_B. Cubes
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
2
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long mod = 1000000009; map<pair<int, int>, int> mp; int x[100005], y[100005], m; vector<int> fg[100005], rg[100005]; bool v...
CPP