prompt string | response string |
|---|---|
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 5e5 + 10;
template <class T>
inline bool chkmin(T &A, T B) {
return B < A ? A = B, 1 : 0;
}
template <class T>
inline bool chkmax(T &A, T B) {
return A < B ? A = B, 1 : 0;
}
template <const int Maxn, const int Maxm>
struct Link_List {
i... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.function.BiFunction;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.uti... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, q, a[N];
int tree[N << 2];
int pre[N], nxt[N];
int to[N];
vector<pair<int, int> > qry[N];
vector<int> toConsider[N];
int idx;
int ans[N];
void upd(int node, int s, int e, int idx, int v) {
if (s == e) {
tree[node] = v;
return;
}
i... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
static Reader scan;
static PrintWriter pw;
static int n,q;
static int arr[],prev[],left[],right[];
static int max_right_in_pref_val[][],max_right_in_pref_max_right_val[][],tree_left[][],tree_right[][],tree_val[... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 500010;
inline int read() {
int x(0), w(1);
char c = getchar();
while (c ^ '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') w = -1, c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
return x * w;... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
const uint32_t MAX_N = 5.1e5;
template <typename T, size_t N>
class SegmentTree {
private:
T data[2 * N];
public:
SegmentTree() { std::fill(data, data + 2 * N, T()); }
void update(uint32_t l, uint32_t r, const T &val) {
for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
if (l & ... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
int n, i, q, l, r;
int a[500005];
int last[500005];
int ansv[500005];
vector<pair<int, int>> qv[500005];
vector<pair<int, int>> seg;
void upd(int i, int st, int dr, int p, int val) {
if (st == dr) {
seg[p] = {val, st};
return;
}
int mij = (st + dr) / 2;
if (... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 600000;
const int INF = 99999999;
int n, q;
int a[maxn], pre[maxn], tmp[maxn], ans[maxn];
struct nod {
int num, pre;
};
struct nod1 {
int l, f;
};
vector<nod1> v[maxn];
nod seg[maxn * 5];
bool operator<(nod a, nod b) { return a.pre < b.pre; }
inline voi... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int MODN = 1e9 + 7;
int rs[500005], ra, ff;
int ou[500005];
int ns[500005];
int ab[1000];
struct query {
int l, r, in;
} qs[500005];
bool compare(query &q1, query &q2) {
if (q1.l / ra != q2.l / ra) {
return q1.l < q2.l;
}
if ((q1.l / ra) & 1) {
return ... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
const int ms = 500500;
int n;
std::vector<std::pair<int, int> > tree[ms + ms];
int id[ms];
std::vector<std::pair<int, int> > range(ms, std::pair<int, int>(0, 0));
void add(int l, int r, std::pair<int, int> v) {
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l & 1) {
tree[l++].pus... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int sz = 800;
int arr[555555], seg[555555], ans[555555], ch[555555], nu[888];
vector<pair<int, pair<int, int> > > inf[888];
bool tmr(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
return a.second.first < b.second.first;
}
int main(void) {
int n;
s... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
int arr[500005], brr[500005];
pair<int, int> tree[500005 * 4];
vector<int> vv[500005];
vector<pair<int, int> > qr[500005];
int ans[500005];
void build(int node, int b, int e) {
if (b == e) {
tree[node] = make_pair(500000000, 500000000);
return;
}
int left = 2 ... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int pre[maxn], las[maxn], a[maxn], ans[maxn];
struct node {
int x, y;
bool operator<(const node &b) const { return x < b.x; }
};
node t[maxn << 2];
vector<node> Q[maxn];
void upt(int o, int l, int r, int p, node v) {
if (l == r) {
t[o] =... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 500010, M = 1333333;
int n, m, i, j, a[N], pre[N], nxt[N], vis[N], L[N], R[N], NXT[N], G[N], ans[N];
int Gp[N], Nxt[N];
pair<int, int> v[M];
inline void up(pair<int, int>& a, const pair<int, int>& b) {
if (a < b) a = b;
}
void change(int x, int a, int b, int... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
struct LHQ {
int st[500001], tp;
int ps[500001];
void ins(int x) {
st[ps[x] = (++tp)] = x;
return;
}
void era(int x) {
st[ps[st[tp]] = ps[x]] = st[tp];
tp--;
return;
}
int qry() {
if (tp == 0) return 0;
return st[1];
}
} b;
int n,... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numCh... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 400, S = 1500;
int n, q, a[N], licz[N], wynik[N];
struct Zap {
int L;
int R;
int grupa;
int indeks;
} T[N];
bool funkcja(const Zap &A, const Zap &B) {
if (A.grupa != B.grupa) return A.grupa < B.grupa;
return (A.grupa & 1) ? (A.R > B.R) : (A.R... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 500500;
int n, q, a[N];
int to[N], idx[N];
int ans[N];
pair<int, int> seg[N << 2];
vector<pair<int, int> > qry[N];
void upd(int i, int l, int r, int j, int val, int who) {
if (j < l || j > r) return;
if (l == r) {
seg[i] = {val, who};
return;
}
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
struct query {
long l, r, id;
};
long n, m, tmp, a[500005], last[500005];
long ans[500005];
query q[500005];
pair<long, long> st[2000005];
void update(long id, long l, long r, long i, long x) {
if (l > i || r < i) {
return;
}
if (l == r) {
st[id].first = x;
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 500500;
struct node {
int l, r, ID, num;
} q[Maxn];
int ans[Maxn], kind[Maxn];
int as[Maxn];
char vis[Maxn];
int b, n, m;
inline bool cmp(const node &x, const node &y) {
if (x.l / b < y.l / b) return 1;
if (x.l / b > y.l / b) return 0;
return ((x.l ... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 500500;
int n, q, a[N], nxt[N], pos[N], ans[N];
struct S {
int f = 0, s = 0;
} tr[N * 4];
vector<pair<int, int> > v[N];
void up(int d, int l, int r, int i, int v, int j) {
if (i < l || i > r) return;
if (l == r)
tr[d].f = v, tr[d].s = j;
else {
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 10, M = int(5e5) + 10, mod = int(1e9) + 7;
int n, a[M], lx[M], rx[M], q, lp[N + 2], last[N];
vector<pair<int, pair<int, int> > > t[4 * M];
vector<pair<int, int> > mx[4 * M];
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v].push_back(ma... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* @author khokharnikunj8
*/
public class Main {
public static void main(S... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5, inf = 1e6;
int mi[maxn * 4 + 5];
int a[maxn + 5], pre[maxn + 5], now[maxn + 5];
int ans[maxn + 5];
int n, m;
vector<pair<int, int> > q[maxn + 5];
void update(int k) {
mi[k] = mi[k * 2];
if (pre[mi[k * 2 + 1]] < pre[mi[k]]) mi[k] = mi[k * 2 + 1];
}
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 10;
struct query {
int l, r, id;
} Q[maxn];
int n, q, a[maxn], pos[maxn], ans[maxn];
struct st {
struct node {
int l, r;
pair<int, int> min;
} tree[maxn << 2];
inline void bulid(int i, int l, int r) {
tree[i].l = l;
tree[i]... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5;
int n, bs, q, a[mxN], ans[mxN], cnt[mxN + 1];
vector<int> v;
bool inv[mxN + 1];
struct query {
int l, r, i;
inline bool operator<(const query &o) const {
if (l / bs != o.l / bs) return l < o.l;
return l / bs & 1 ? r < o.r : r > o.r;
}
} qs... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
long long hilbertorder(int x, int y, int lg) {
long long ret = 0;
for (int s = lg - 1; s >= 0; --s) {
int rx = x >> s & 1, ry = y >> s & 1;
ret = (ret << 2) | ((rx * 3) ^ ry);
if (!ry) {
if (rx) x = (1 << lg) - 1 - x, y = (1 << lg) - 1 - y;
swap(... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const long long int MAXN = 5e5 + 5;
const long long int N = 1e6 + 5;
long long int n, m;
long long int BLOCK = 555;
struct query {
long long int l, r, i;
inline bool oper... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline int read() {
int x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
int n, m, t;
int sq[500005... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
int last[500005];
int a[500005], b[500005], ans[500005];
vector<pair<int, int> > v[500005];
pair<int, int> st[2000005];
pair<int, int> min(pair<int, int> a, pair<int, int> b) {
if (a.first < b.first) return a;
return b;
}
void update(int n, int s, int e, int idx, int v)... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int Max = 500500;
int n, a[Max], q, cnt[Max], outp[Max], belong[Max];
char vis[Max];
vector<int> ans;
struct node {
int l, r, id;
} que[Max];
int cmp(const node& a, const node& b) {
if (belong[a.l] == belong[b.l]) {
if (belong[a.l] & 1) {
return belong[a... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcs... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const long long ts = 500050;
int n, m, b, l = 1, r, a[ts], c[ts];
bool f[ts];
struct query {
int l, r, id, ans;
} q[ts];
vector<int> d;
inline bool cmp(const query &x, const query &y) {
if (x.l / b < y.l / b) return 1;
if (x.l / b > y.l / b) return 0;
return ((x.l /... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
struct Query {
int id, l, r, solution;
Query() {}
void olvas(int i) {
id = i;
cin >> l >> r;
l--;
r--;
}
const bool operator<(Query masik) const { return r < masik.r; }
};
const int maxn = 500005;
vector<Query> task;
int n, q;
int a[maxn], f[maxn];... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int big = 2e9;
const int md = 1e9 + 7;
int n, a[N], l[N], r[N], last[N], q, ll, rr, ans[N];
vector<int> sp[N];
pair<int, int> t[N * 4];
void update(int v, int l, int r, int ps, int vl) {
if (l == r) {
t[v].first = vl;
t[v].second = l;
... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
int n, q, a[500005], ans[500005], tmp, lastl, lastr, cnt[500005], count1,
cntsqrt[715];
pair<pair<int, int>, int> queries[500005];
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
if ((a.first.first / tmp) != (b.first.first / tmp))
return (a.fi... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
vector<pair<int, int>> qr[500005];
int last[500005];
int t[1000005];
int res[500005];
int query(int l, int r) {
int res = 1e9;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = min(res, t[l++]);
if (r & 1) res = min(res, t[--... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500000;
const int MAX_Q = 500000;
const int MAX_V = 500000;
struct Data {
int l, r;
int index;
bool type;
bool operator<(const Data& other) const {
if (this->r == other.r) return this->type < other.type;
return this->r < other.r;
}
} q[MA... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int n = 0;
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
n = (n << 1) + (n << 3) + (c ^ 48);
c = getchar();
}
return n;
}
struct Que {
int i, l, r;
};
bool Cmp(Que A, Que B) {... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import javafx.util.Pair;
public class Solve5 {
public static void m... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10, inf = 0x3f3f3f3f;
int arr[maxn], pre[maxn], ans[maxn];
pair<int, int> tree[maxn << 2];
struct query {
int l;
int r;
int id;
} q[maxn];
bool cmp(query a, query b) {
if (a.r == b.r)
return a.l < b.l;
else
return a.r < b.r;
}
inline... |
Problem: You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a subarray is a contiguous subsegment of an array). For example, if ... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
using namespace std;
const int maxn = (int)(5e5 + 5);
const long long mod = (long long)(1e9 + 7);
int l[maxn], r[maxn], a[maxn];
int pos[maxn];
ve... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
struct {
inline operator int() {
int x;
return scanf("%d", &x), x;
}
inline operator long long() {
long long x;
return scanf("%lld", &x), x;
}
template <class T>
inline void operator()(T &x) {
x = *this;
}
template <class T, class... A>
inline void operator... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int n, a[500 + 5], p[500 + 5];
int main() {
register int i;
for (scanf("%d", &n), i = 1; i <= n; ++i) p[i] = 1;
for (i = 1; i <= n; ++i)
scanf("%d", a + i), ~a[i] && (p[a[i]] = 2LL * p[a[i]] % 1000000007);
register int t = 1;
for (i = 1; i ^ n; ++i) t = 2LL * ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30, mod = 1e9 + 7, maxn = 2333333;
int pw(int x, int y) {
if (!y) return 1;
if (y == 1) return x;
int mid = pw(x, y >> 1);
if (y & 1) return 1ll * mid * mid % mod * x % mod;
return 1ll * mid * mid % mod;
}
int cnt[200005];
int curc0, curc;
int... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int n;
int cnt[505];
long long bin[505];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a != -1) cnt[a]++;
}
bin[0] = 1;
for (int i = 1; i < 505; i++) bin[i] = bin[i - 1] * 2LL % 1000000007;
long long ans = bin[n - 1] - 1;
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | m = 1000000007
n = int(input())
a = list(map(int, input().split()))
print((pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1)) % m) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long NMAX = 2e5;
long long followed[NMAX + 2], isactive[NMAX + 2];
const long long MOD = 1e9 + 7;
long long put2(long long p) {
long long r = 1;
for (long long i = 1; i <= p; ++i) r = r * 2LL % MOD;
return r;
}
int main() {
long long N;
cin >> N;
long... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, a[507], sze[507], ans;
long long ksm(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1) res = res * a % mod;
return res;
}
int main() {
scanf("%lld", &n);
for (long long i =... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, in2 = 500000004;
inline long long max(long long x, long long y) { return (x > y ? x : y); }
inline long long min(long long x, long long y) { return (x < y ? x : y); }
long long n, id[510], val[510], cnt, s;
inline long long Pow(long long x,... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
namespace Acc {
const int N = 5e2 + 10;
const int mod = 1e9 + 7;
int a[N], ans, n, x;
int qpow(int a, int b) {
int res = 1;
for (; b; a = 1ll * a * a % mod, b >>= 1)
if (b & 1) res = 1ll * res * a % mod;
return res % mod;
}
int work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
long long mod_pow(long long x, long long n) {
long long res = 1;
for (; n > 0; n >>= 1) {
if (n & 1) res = res * x % Mod;
x = x * x % Mod;
}
return res;
}
int cnt[600];
void add(int &a, long long b) { a = (a + b) % Mod; }
int main() ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long int x, n, a[555], R, p[555] = {1}, M = 1e9 + 7;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i)
p[i] = p[i - 1] * 2 % M, cin >> x, ~x ? a[x]++ : 0;
R = p[n - 1] - 1;
for (int i = 1; i <= n; ++i) R -= p[a[i]] - 1;
cout << (R % M + M) % M;
}
|
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using ul = std::uint32_t;
using li = std::int32_t;
using ull = std::uint64_t;
using ll = std::int64_t;
using vul = std::vector<ul>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;
using vvvb = std::vector<vvb>;
std::mt19937_64 rands;
ul n;
vul ans(501, 1);
const ul base = 1e9 + 7;
ul... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int grp[501];
const int MOD = 1e9 + 7;
int pow2[501];
int main() {
pow2[0] = 1;
for (int i = 1; i <= 500; i++) {
pow2[i] = pow2[i - 1] * 2;
pow2[i] %= MOD;
}
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
if (k == -1) {
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long read() {
long long w = 0, f = 1;
char c = ' ';
while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
return w * f;
}
const long long mod = 1e9 + 7;
long long pown(long long x, lo... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn];
int pw[maxn];
const int mod = 1e9 + 7;
int f(int x) {
int res = 1 - pw[x - 1];
res %= mod;
res = (res + mod) % mod;
return res;
}
int main() {
pw[0] = 1;
for (int i = (1); i < (maxn); ++i) pw[i] = pw[i - 1] * 2 % mod;
int n;
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using INT = long long;
const int mod = 1e9 + 7;
int c(int n) {
int ans = 1;
for (int i = 1; i <= n; i++) ans = ans * 2 % mod;
return ans;
}
int cnt[11111];
int main() {
int n;
cin >> n;
int k = 0;
for (int i = 1; i <= n; i++) {
int u;
scanf("%d", &u);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 505, MOD = 1000000007;
int n, cnt[MAXN];
int qmi(int x, int k) {
int ans = 1;
for (; k; k >>= 1, x = (long long)x * x % MOD)
if (k & 1) ans = (long long)ans * x % MOD;
return ans;
}
int main() {
int x;
scanf("%d", &n);
for (int i = 1; i <= n... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, Mod = 1e9 + 7;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}
inline int ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int fa[100010];
int se[100010];
int n;
long long ksm(long long a, int n, long long c = 1) {
for (; n; n >>= 1, a = a * a % mod)
if (n & 1) c = c * a % mod;
return c;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 500;
const int P = int(1E9) + 7;
inline int add(int x, int y) {
x += y;
return x >= P ? x - P : x;
}
inline int sub(int x, int y) {
x -= y;
return x < 0 ? x + P : x;
}
inline int mul(int x, int y) { return (int)(1LL * x * y % P); }
int mpow(int b, int ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int N = 505, mod = 1000000007;
int n, a[N], s;
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n;
for (int i = 1; i <= n; ++i) {
int x;
std::cin >> x;
if (~x) a[x] = (a[x] * 2 + 1) % mod;
}
for (int i = 1; i < n; ++i) s = (s * 2 + 1) % mod;
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | from fractions import Fraction
from copy import copy
from random import randint
from collections import *
import sys
sys.setrecursionlimit(1500)
class F:
def __init__(self,m,n):
self.m = m
self.n = n
self.save = {}
def __call__(self,a):
if a in self.save:
return self.... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-') f = -1;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + ch - 48;
}
return x * f;
}
const int mxN = 500;
const int P = 1e9 + 7;
int cnt... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int bit[510];
int u, cnt[510], n;
int main() {
scanf("%d", &n);
bit[0] = 1;
for (int i = 1; i <= n; i++) bit[i] = (bit[i - 1] << 1) % 1000000007;
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (u != -1) cnt[u]++;
}
int ans = bit[n - 1] - 1;
for (in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, res, t[505];
int read() {
int x = 0, fl = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') fl = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = get... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, mod = 1e9 + 7;
template <typename T>
inline void cmax(T &first, T second) {
if (first < second) first = second;
}
template <typename T>
inline void cmin(T &first, T second) {
if (second < first) first = second;
}
using namespace std;
int n, h[N], ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long int mod(long long int a) {
return (a % 1000000007 + 1000000007) % 1000000007;
}
long long int calc(int n) {
if (n == 0) return 1;
if (n == 1) return 2;
long long int ca = calc(n / 2);
if (n % 2) return mod(2 * ca * ca);
return mod(ca * ca);
}
int main(... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int n, a[500];
long long pot[500];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = (1); i < (n); i++) pot[i] = (2 * pot[i - 1] + 1) % 1000000007;
for (int i = 0; i < (n); i++) {
int p;
cin >> p;
if (p >= 1) a[p - 1]++;
}
lo... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using INT = long long;
int power(int a, int b, int mod, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % mod)
if (b & 1) ans = 1LL * ans * a % mod;
return ans;
}
const int mod = 1e9 + 7;
int a[555], b[555];
int main() {
int n;
scanf("%d", &n);
INT ans = pow... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
run();
return 0;
}
int uplg(int n) { return 32 - ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int read() {
int s = 0, t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') t = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * t;
}
int pw[510], c[510];
void upd(int &x, int y)... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int mod = 1000000007;
int n;
int pw2[540], size[540];
int main() {
int i, x;
long long s = 0;
scanf("%d", &n);
for (*pw2 = i = 1; i <= n; ++i)
pw2[i] = pw2[i - 1] * 2 % mod, scanf("%d", &x), ~x && ++size[x];
for (i = 1; i <= n; ++i) s -= pw2[size[i]] - 1;
s = (s + pw2[n - ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
bool chmax(t& first, u second) {
if (first < second) {
first = second;
return true;
} else
return false;
}
template <class t, class u>
bool chmin(t& first, u second) {
if (second < first) {
first = seco... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50, mod = 1e9 + 7;
int n, a[N], T, k, pw[N], ans;
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++) pw[i] = 2 * pw[i - 1] % mod;
for (int i = 1, x; i <= n; i++) scanf("%d", &x), ~x ? a[x]++ : 0;
for (int i = 1; i <= n; i++) ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll inv2 = (mod + 1) / 2;
ll qpow(ll a, ll n) {
ll r = 1;
for (; n; n >>= 1) {
if (n & 1) r = r * a % mod;
a = a * a % mod;
}
return r;
}
const int N = 510;
ll a[N][N];
int p[N], cnt[N];
int n;
void solve... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar(), f = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
}
int n, sz[505],... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int sum(int a, int b) { return (a + b) % MOD; }
int prod(int a, int b) { return a * 1ll * b % MOD; }
int mod_pow(int b, int e) {
if (!e) return 1;
if (e & 1) return prod(b, mod_pow(b, e - 1));
return mod_pow(prod(b, b), e / 2);
}
int main() {
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-5;
const int maxn = 100000 + 10;
const int mod = 1e9 + 7;
int a, b[505], n;
int main() {
memset(b, 0, sizeof(b));
long long ans = 0;
int tmp;
scanf("%d", &n);
for (int i = 1; i <= n - 1; i++) ans = (2 * ans + 1) % mod;
for (int i = 1; i <... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int cnt[505];
long long pow2[505];
int main() {
int n, id;
long long ans;
scanf("%d", &n);
memset(cnt, 0, sizeof(cnt));
pow2[0] = 1;
for (int i = 1; i <= n; i++) {
pow2[i] = pow2[i - 1] * 2 % mod;
scanf("%d", &id);
if (... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
int n, a[505], S[505];
int F(int x) {
int s = 1;
for (int i = (int)(1); i <= (int)(x); i++) s = 2ll * s % mo;
return s - 1;
}
int main() {
scanf("%d", &n);
for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
for (int i = (in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int Power(int x, int y) {
int ret = 1;
while (y) {
if (y & 1) ret = 1ll * ret * x % mod;
x = 1ll * x * x % mod, y >>= 1;
}
return ret;
}
int s[505], ans, n;
int main() {
scanf("%d", &n), ans = Power(2, n - 1) - 1;
for (int i = 1,... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
namespace Acc {
const int N = 5e2 + 10;
const int mod = 1e9 + 7;
int a[N], ans, n, x;
int qpow(int a, int b) {
int res = 1;
for (; b; a = 1ll * a * a % mod, b >>= 1)
if (b & 1) res = 1ll * res * a % mod;
return res % mod;
}
int work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int sz[100100], n, ans = 0;
int qpow(int a, int b) {
int ans = 1;
for (; b; b >>= 1, a = 1ll * a * a % 1000000007)
if (b & 1) ans = 1ll * ans * a % 1000000007;
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; ++i) {
scanf("%d", &x);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | mod=10**9+7
n=int(input())
a=input().split()
ans=pow(2,n-1,mod)-1
sz=[0]*(n+1)
for i in a:
i=int(i)
if i!=-1:
sz[i]+=1
for i in range(1,n+1):
ans-=pow(2,sz[i],mod)-1
print((ans%mod+mod)%mod) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 511;
const int MOD = 1000000007;
int sr;
int sum(int a, int b) {
sr = a + b;
if (sr >= MOD) sr -= MOD;
return sr;
}
int N;
int Cnt[MAXN];
int Pow[MAXN], Ans;
int main() {
ios_base::sync_with_stdio(false);
cin >> N;
Pow[0] = 1;
for (int i = 1; ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int MAXN = 500;
const int MOD = 1000000007;
inline int Add(int x, const int &y) { return (x += y) >= MOD ? x - MOD : x; }
inline int Sub(int x, const int &y) { return (x -= y) < 0 ? x + MOD : x; }
inline int Mul(const int &x, const int &y) { return (long long)x * y % MOD; }
int Pow(int x,... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | input();a=input().split();print((pow(2,len(a)-1)-1-sum(pow(2,a.count(x))-1for x in{*a}-{'-1'}))%(10**9+7)) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | input();a=input().split();print((2**(len(a)-1)-1-sum(2**a.count(x)-1for x in{*a}-{'-1'}))%(10**9+7)) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n;
int in[N];
int cnt[N];
int fast(int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = (1LL * ret * a) % MX;
b >>= 1;
a = (1LL * a * a) % MX;
}
return ret;
}
i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
int const mod = 1e9 + 7;
inline int fpow(int a, int b) {
int ans = 1;
for (; b; b >>= 1, a = 1ll * a * a % mod)
if (b & 1) ans = 1ll * ans * a % mod;
return ans;
}
int n, c[510], ans;
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; i++) {
scanf("%d", &x);
if (~x) ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int bit[510];
int u, cnt[510], n;
int main() {
scanf("%d", &n);
bit[0] = 1;
for (int i = 1; i <= n; i++) bit[i] = (bit[i - 1] << 1) % 1000000007;
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (u != -1) cnt[u]++;
}
int ans = bit[n - 1] - 1;
for (in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.