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 |
|---|---|---|---|---|---|
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
vector<int> a(n);
for (int &x : a) cin >> x;
set<int> X;
for (int i = 0; i < n; i++) X.insert(i);
map<int, pair<int, int>> mp;
set<pair<int... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
if (a < 0) return gcd(-a, b);
if (b < 0) return gcd(a, -b);
return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
if (a < 0) return lcm(-a, b);
if (b < 0) return lcm(a, -b);
return a * (b /... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 + 200000;
int n;
struct pnt {
int c, u, v;
pnt(int _c = 0, int _u = 0, int _v = 0) : c(_c), u(_u), v(_v) {}
bool operator<(const pnt& op) const {
if (c != op.c) return c < op.c;
if (u != op.u) return u < op.u;
return v < op.v;
}
};
se... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int le[250000];
int ri[250000];
int arr[250000];
bool mark[250000];
priority_queue<pair<int, pair<int, int> > > pq;
vector<pair<int, int> > v;
int checkle(int x) {
if (le[x] == x) return x;
return le[x] = checkle(le[x]);
}
int checkri(int x) {
if (ri[x] == x) return x... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 |
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class C {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
char[] arr2 = ... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
class W {
public:
int c;
int l;
W() {}
W(int a, int b) {
c = a;
l = b;
}
bool operator<(const W &q) const {
return (c < q.c) || (c == q.c && l < q.l);
}
bool operator==(const W &q) const { return c == q.c && l == q.l; }
};
class T {
public:
i... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
long long l[N], r[N];
long long a[N];
bool used[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
string second;
cin >> second;
for (long long i = 0; i < n; ++i) cin >> a[i];
set<pair<long long,... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > S;
set<pair<int, int> >::iterator it;
int a[220000], prv[220000], nxt[220000];
char s[220000];
int main() {
int n, i, j, l, r;
cin >> n >> s;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) prv[i] = i - 1, nxt[i] = i + 1;
for (i... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.util.*;
import java.io.*;
/*
6
BBGBGG
6 4 3 7 5 1
*/
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > heap;
vector<pair<int, int> > ans;
int N, a[1000009], n[1000009], p[10000009], u[10000009];
char g[10000009];
int fn(int first) {
if (u[n[first]]) n[first] = fn(n[first]);
return n[first];
}
int fp(int first) {
if (u[p[first]]) p[fi... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import heapq,sys
q=[]
c=0
n=int(input())
s=input()
a=list(map(int,input().split()))
l=[i-1 for i in range(n)]
r=[i+1 for i in range(n)]
for i in range(n-1):
if s[i]!=s[i+1]:
heapq.heappush(q,(abs(a[i]-a[i+1]),i,i+1))
c+=1
ans=[]
while c>0:
t,i,j=heapq.heappop(q)
c-=1
if r[i]==-1 or r[j]==-1:
continue
ans.app... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import heapq
n = int(input())
gender = [char for char in input()]
a = [int(i) for i in input().split()]
difference = []
couple = []
left = [i - 1 for i in range(n)]
right = [i + 1 for i in range(n)]
for i in range(1,n):
if gender[i] != gender[i - 1]:
heapq.heappush(difference,(abs(a[i] - a[i - 1]),i - 1,i)... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXn = 2 * 100000 + 100;
int n;
char s[MAXn];
int a[MAXn];
int prv[MAXn], nxt[MAXn];
bool gone[MAXn];
struct couple {
int left, right;
couple(int left, int right) : left(left), right(right) {}
bool operator<(couple X) const {
return abs(a[left] - a[right... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
const long long inf = 1e9 + 44;
const int MAX = 3e5 + 9;
const long long MOD = 1e9 + 7;
const double eps = 1e-10;
double const PI = 3.1415926535897931;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void _print(vector<int> v) {
cout << "[ ";
for (auto u : v) cout... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 110000;
int a[MAXN];
int L[MAXN], R[MAXN];
char C[MAXN];
bool was[MAXN];
struct Pair {
int id1;
int id2;
Pair(int id1 = 0, int id2 = 0) {
this->id1 = id1;
this->id2 = id2;
}
bool operator<(const Pair& p) const {
if (abs(a[id1] - a[... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MAXN = 2e5 + 5;
int a[MAXN];
char s[MAXN];
int l[MAXN], r[MAXN];
vector<pair<int, int> > v;
bool vis[MAXN];
int main() {
int m, n, i, j, k;
scanf("%d", &m);
for (i = 1; i <= m; i++) l[i] = i - 1, r[i] = i + 1, vis[i] = 1;
scanf("%s", s... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.util.*;
import java.io.*;
public class helloworld {
static long fact[];
static long max;
static int ans;
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
greater<pair<int, pair<int, int>>>>
q;
int n;
unordered_set<int> s;
set<int> unseen;
cin >> n;
string str;
cin >> str;
vector<int> arr(n);
for ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
char s[200005];
int v[200005];
struct node {
int l, r, v;
void init(int ll, int rr, int vv) {
l = ll;
r = rr;
v = vv;
}
friend bool operator<(const node& a, const node& b) {
if (a.v != b.v) return a.v > b.v;
return a.l > b.l;
}
} n1;
pri... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
struct Node {
int l, r, s;
};
struct Pair {
int p1, p2, d;
Pair(int p1, int p2, int d) : p1(p1), p2(p2), d(d) {}
bool operator>(const Pair& rhs) const {
return d > rhs.d || (!(rhs.d > d) && p1 > rhs.p1);
}
};
int main() {
int n;
std::string s;
std::cin >> n >> s;
std::vect... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | // Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new F... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct man {
int l, r;
};
bool U[200010];
man sosed[200010];
int skill[200010];
char sex[200010];
int main() {
int n;
cin >> n;
priority_queue<pair<int, int> > Q;
for (int i = 0; i < n; ++i) {
cin >> sex[i];
}
for (int i = 0; i < n; ++i) {
cin >> skill... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 250000;
bool vis[maxn];
int sk[maxn];
int ll[maxn], rr[maxn];
char s[maxn];
int n;
struct node {
int u, v, val;
};
bool operator<(const node a, const node b) {
if (a.val != b.val) return a.val > b.val;
return a.u > b.u;
}
priority_queue<node> q;
int m... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct Node {
int val;
int left, right;
};
struct cmp {
bool operator()(const Node& lhs, const Node& rhs) {
if (lhs.val != rhs.val) {
return lhs.val > rhs.val;
} else {
return lhs.left > rhs.left;
}
}
};
int main() {
ios::sync_with_stdio(0)... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic warning "-Wall"
int main() {
ios::sync_with_stdio(false);
int n;
string sex;
cin >> n;
cin >> sex;
vector<int> skill(n);
for (typeof(n) i = (0); i < (n); i++) cin >> skill[i];
vector<int> prev(n);
prev[0] = -1;
for (typeof(n) i = (... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct Event {
int d, a, b;
Event(int _d, int _a, int _b) : d(_d), a(_a), b(_b) {}
bool operator<(const Event &x) const {
if (d != x.d) return d > x.d;
return min(a, b) > min(x.a, x.b);
}
};
const int MN = 200009;
char T[MN];
int D[MN];
set<int> K;
vector<pa... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int M = 1000000;
int n;
char s[M];
int xs[M];
bool used[M];
struct S {
int l, r;
S() {}
S(int a, int b) : l(a), r(b) {}
bool operator<(const S& s) const {
const int a = abs(xs[l] - xs[r]), b = abs(xs[s.l] - xs[s.r]);
return a > b || a == b && l > s.l;
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long INF = 100000000000000000;
const int MAXN = 3 * 100000;
struct T {
int left, right, diff;
bool operator>(const T& other) {
if (diff != other.diff) return diff < other.diff;
return left < other... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct thing {
int L;
int R;
int V;
bool operator<(const thing &th) const {
if (V > th.V || (V == th.V && L > th.L)) return true;
return false;
}
} in;
priority_queue<thing> work;
int N, give;
bool b[200010];
int v[200010];
bool ed[200010];
int L[200010];
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
struct BG {
int diff;
int pos;
int second;
BG() {}
BG(int diff, int pos, int second) : diff(diff), pos(pos), second(second) {}
bool operator<(BG const& p) const {
if (diff != p.diff) return diff > p.diff;
return pos > p.pos;
}
};
struct Using {
int n;
std::vector<int> ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int skil[200007], pre[200007], post[200007];
bool flag[200007];
char s[200007];
struct data {
int l, r;
data() {}
data(int a, int b) {
l = a;
r = b;
}
bool operator<(const data& a) const {
return abs(skil[l] - skil[r]) == abs(skil[a.l] - skil[a.r])
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import heapq as hq
n=int(input())
s=input()
a=list(map(int,input().split()))
pre=[i-1 for i in range(n)]
nxt=[i+1 for i in range(n)]
free=[1 for i in range(n)]
line=[(abs(a[i]-a[i+1]),i,i+1) for i in range(n-1) if s[i]!=s[i+1]]
#print(line)
hq.heapify(line)
ans=[]
while line:
t,ppre,pnxt=hq.heappop(line)
if fr... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<int> v;
struct po {
int diff;
int l;
int r;
bool operator()(const po& l, const po& r) {
if (l.diff == r.diff) {
if (l.l == r.l) return l.r > r.r;
return l.l > r.l;
}
return l.diff > r.diff;
}
};
vector<po> ans;
int vis[200005];
set<i... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import heapq
import math
n = int(raw_input())
bg = raw_input()
bn = bg.count('B')
skill = [int(i) for i in raw_input().split()]
couple = []
num = []
for i in range(n-1):
if bg[i] != bg[i+1]:
diff = abs(skill[i] - skill[i+1])
couple.append([diff, i, i+1])
heapq.heapify(couple)
flag = [0] * n
before = [int(i) f... | PYTHON |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 |
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer s = new... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int n;
struct man {
int _dsfdsf;
int _dfjdsj;
void setLeft(int x) {
if (x < 0 || x >= n) x = -1;
_dsfdsf = x;
}
void setRight(int x) {
if (x < 0 || x >= n) x = -1;
_dfjdsj = x;
}
void remove();
};
char... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
for (int(i) = ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int skil[200007], pre[200007], post[200007];
bool flag[200007];
char s[200007];
struct data {
int l, r;
data() {}
data(int a, int b) {
l = a;
r = b;
}
bool operator<(const data& a) const {
return abs(skil[l] - skil[r]) == abs(skil[a.l] - skil[a.r])
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int skill[100011 * 2], vis[100011 * 2];
int rgh[100011 * 2], lf[100011 * 2];
int cup, n;
char s[100011 * 2];
struct node {
int l, r, c;
bool operator<(const node &a) const {
if (c == a.c)
return l > a.l;
else
return c > a.c;
}
} tmp;
priority_queue... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int pre[maxn], net[maxn], val[maxn];
char str[maxn];
struct Node {
int l, r, val;
Node(int l = 0, int r = 0, int val = 0) : l(l), r(r), val(val) {}
bool operator<(const Node &rhs) const {
return val > rhs.val || (val == rhs.val && l > rh... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
template <class T>
void swap(T &x, T &y) {
T t = x;
x = y;
y = t;
}
int abs(int x) { return (x < 0 ? -x : x); }
const int N = 200009;
int n, prev[N], next[N], a[N], l, h, u[N];
char s[N];
class point {
public:
int a, x, y;
bool operator>(const point &t) { return (a > t.a || (a == t.a... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.io.*;
import java.util.*;
//School Team Contest #3 (Winter Computer School 2010/11), C
public class DancingLessons2 {
private static class Person implements Comparable<Person> {
final boolean sex;
final int skill;
final int position;
Person(int position, boolean sex, int skill) {
this.sex = se... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int i = int(0); i <= int((static_cas... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import heapq
import math
n = int(raw_input())
bg = raw_input()
bn = bg.count('B')
skill = [int(i) for i in raw_input().split()]
couple = []
num = []
for i in range(n-1):
if bg[i] != bg[i+1]:
diff = abs(skill[i] - skill[i+1])
couple.append([diff, i, i+1])
heapq.heapify(couple) #以两数差值为选择的序号堆排序
flag = [0] * n... | PYTHON |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
char s[200022];
int ans[200022][3];
int ansLen;
int abs(int a) { return a < 0 ? -a : a; }
int Diff(int a, int b) {
if (a < 0 && b > 0 || a > 0 && b < 0) return abs(a + b);
return 1000000000;
}
struct bnode {
int num;
bnode *pre, *next;
int d[500];
int min... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
int n;
struct Node {
int left;
int right;
int diff;
};
int ll[N];
int rr[N];
int level[N];
char sex[N];
bool vis[N];
struct cmp {
bool operator()(Node x, Node y) {
if (x.diff != y.diff)
return x.diff > y.diff;
else
ret... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
int a[MAXN], n;
set<int> ind;
set<pair<int, pair<int, int> > > x;
string s;
void rem(int p, int q) {
ind.erase(p);
ind.erase(q);
auto l = ind.lower_bound(p);
auto r = ind.lower_bound(q);
if (l != ind.begin()) {
--l;
x.erase({abs(a... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | from heapq import heappush,heappop,heapify
n=int(input())
symbols=input()
skl=list(map(int,input().split()))
LMap=[i-1 for i in range(n+1)]
RMap=[i+1 for i in range(n+1)]
LMap[1],RMap[n]=1,n
h=[]
res=[]
cnt=0
B=symbols.count("B")
N=min(n-B,B)
ind=[True]*(n+1)
for i in range(n-1) :
if symbols[i]!=symbols[i+1] :
... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.io.*;
import java.util.*;
//School Team Contest #3 (Winter Computer School 2010/11), C
public class DancingLessons {
private static class Person implements Comparable<Person> {
final boolean sex;
final int skill;
final int position;
Person(int position, boolean sex, int skill) {
this.sex = sex... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int INF = ~0u / 2;
struct Node {
int left, right, key;
};
bool operator<(Node a, Node b) {
if (a.key != b.key)
return a.key < b.key;
else if (a.left != b.left)
return a.left < b.left;
return a.right < b.right;
}
int n;
string s;
int List[(2 * 100000) +... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | from heapq import heappush,heappop,heapify
n=int(input())
symbols=input()
skl=list(map(int,input().split()))
LMap=[i-1 for i in range(n+1)]
RMap=[i+1 for i in range(n+1)]
LMap[1],RMap[n]=1,n
h=[]
res=[]
cnt=0
B=symbols.count("B")
N=min(n-B,B)
ind=[True]*(n+1)
h=[]
for i in range(n-1) :
if symbols[i]!=symbols[i+1] :... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
public class C {
s... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
struct Node {
int l, r, s;
};
struct Pair {
int p1, p2, d;
Pair(int p1, int p2, int d) : p1(p1), p2(p2), d(d) {}
bool operator>(const Pair& rhs) const {
return d > rhs.d || (!(rhs.d > d) && p1 > rhs.p1);
}
};
int main() {
int n;
std::string s;
std::cin >> n >> s;
std::vect... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
char s[1000000];
int a[1000000];
int l[1000000];
int r[1000000];
int visited[1000000] = {0};
int abs(int a) {
if (a < 0) return -a;
return a;
}
int main() {
list<pair<int, int> > ans;
priority_queue<pair<long long, pair<int, int> > > e;
int n;
scanf("%d", &n);
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
struct node {
int d, x, y;
node() {}
node(int a, int b, int c) {
x = a;
y = b;
d = c;
}
bool operator<(const node &a) const {
return d > a.d || (d == a.d && x > a.x) ||
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | from heapq import heappushpop, heapify,heappop,heappush
n=int(input())
danced=[0]*(n+1)
gender=[0]+list(input())
skill=[0]+list(map(int,input().split()))
next=[0]+[i+1 for i in range(1,n)]+[0]
prev=[0]+[i for i in range(n)]
ans=[]
line=[]
total=0
for i in range(1,n):
x,y=i,i+1
if gender[x]==gender[y]:continue
... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline int Abs(int x) { return x > 0 ? x : -x; }
set<int> peo;
set<int>::iterator p1, p2;
bool vis[200050], boy[200050];
char s[200050];
int a[200050];
struct node {
int l, r;
int val;
node(int a = 0, int b = 0, int c = 0) : l(a), r(b), val(c) {}
bool operator<(cons... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | from heapq import heappush,heappop,heapify
n=int(input())
symbols=input()
skl=list(map(int,input().split()))
LMap=[i-1 for i in range(n+1)]
RMap=[i+1 for i in range(n+1)]
LMap[1],RMap[n]=1,n
h=[]
res=[]
cnt=0
B=symbols.count("B")
N=min(n-B,B)
ind=[True]*(n+1)
h=[(abs(skl[i]-skl[i+1]),i+1,i+2) for i in range(n-1) if sym... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct node {
int diff;
int st, ed;
};
bool operator<(node a, node b) {
if (a.diff < b.diff) return 0;
if (a.diff == b.diff && a.st < b.st) return 0;
return 1;
};
struct Out {
int st, ed;
};
Out ans[100005];
char s[2 * 100005];
bool flag[2 * 100005];
int v[2 * 1... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int get_int() {
int val = 0, c = 0;
for (; !isdigit(c); c = getchar())
;
for (; isdigit(c); c = getchar()) val = val * 10 + (c - '0');
return val;
}
struct one {
int s, w, l, r, y;
};
struct two {
int i, j, w;
};
int n, b2_cache = 0;
vector<one> a;
list<two>... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.util.InputMismatchException;
import java.io.*;
import java.util.*;
/**
* Generated by Contest helper plug-in
* Actual solution is at the bottom
*/
public class Main {
public static void main(String[] args) {
InputReader in = new StreamInputReader(System.in);
PrintWriter out = new Pri... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1000 * 100 + 21;
struct couple {
int i, j;
couple(){};
couple(int a, int b) {
i = min(a, b);
j = max(a, b);
}
};
int n;
int a[maxn];
int r[maxn];
int l[maxn];
int b[maxn];
vector<pair<int, int> > ans;
set<couple> s;
bool operator<(const ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct node {
node *left, *right;
int skill, index;
char gender;
};
class item {
public:
node *pos;
int skill, l_index, r_index;
item(node *x) {
assert(x->right != NULL);
node *y = x->right;
l_index = x->index;
r_index = y->index;
skill = ab... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
bool gone[200004];
int main() {
int n, boys = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) boys += (s[i] == 'B');
int arr[n];
map<int, pair<int, int> > mp;
mp[0] = {1, -1};
mp[n - 1] = {n - 2, -1};
for (int i = 0; i < n; i++) {
cin >>... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
set<int> S;
priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >,
greater<pair<int, pair<int, int> > > >
H;
int i, j, k, n, a[222222], nl, nr, sz, aa, bb, u[222222], o;
pair<int, pair<int, int> > pp;
set<pair<int, int> >::iterato... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.util.ArrayDeque;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.io.*;
import java.util.*;
public class Main
{
static final boolean _DEBUG = false;
private static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(BufferedReader _br) {
br = _br;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st ... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
set<pair<int, pair<int, int> > > S;
set<pair<int, pair<int, int> > >::iterator it;
pair<int, int> l[200001];
vector<pair<int, int> > ans;
int a[200001], tag[200001], n;
char s[200001];
int main() {
scanf("%d", &n);
scanf("%s", s);
for (int i = 0; i < n; i++) s[i] = (s... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline long long int modadd(long long int n, long long int m,
long long int p = 1000000007) {
return ((n + m) % p + p) % p;
}
inline long long int modsub(long long int n, long long int m,
long long int p = 1000000007... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000;
char s[MAX_N + 4];
int as[MAX_N], prvs[MAX_N], nxts[MAX_N];
bool used[MAX_N];
vector<pair<int, int> > ps;
struct Stat {
int d, i, j;
Stat() {}
Stat(int _d, int _i, int _j) : d(_d), i(_i), j(_j) {}
bool operator<(const Stat &s) const {
r... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct Node {
int a, i, j;
Node(int a_, int i_, int j_) : a(a_), i(i_), j(j_) {}
friend bool operator>(const Node& p, const Node& q) {
if (p.a > q.a)
return true;
else if (p.a < q.a)
return false;
else if (p.i > q.i)
return true;
else... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long INF = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int n;
vector<int> B, skill, L, R;
int b, g;
string buf;
struct P {
int x, y, dif;
P() {}
P(int a, int b, int c) {
x = a;
y = b;
dif = c;
}
};
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct A {
int l, r;
};
int par[200005];
int p[200005];
int ne[200005];
int fnd(int x) {
if (p[x] == x) return x;
return p[x] = fnd(p[x]);
}
int fnd1(int x) {
if (ne[x] == x) {
return x;
}
return ne[x] = fnd1(ne[x]);
}
int main() {
ios_base::sync_with_stdi... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | //package school3;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class C {
Scanner in;
PrintWriter out;
// String INPUT = "4 BGBG 4 2 4 3";
// String INPUT = "4 BBGG 4 2 4 3";
// String INPUT = "4 BBGG 4 6 1 5";
// String... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct Pair {
int u, v;
};
int t[200000];
int aft[200000], bef[200000];
bool used[200000] = {false};
int abs(int i) { return i > 0 ? i : -i; }
bool operator<(Pair i, Pair j) {
if (abs(t[i.u] - t[i.v]) == abs(t[j.u] - t[j.v]))
if (i.u == j.u)
return i.v < j.v;
... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 200 + 10;
int a[MAXN];
bool boy[MAXN];
vector<pair<int, int> > ans;
struct comp {
const bool operator()(const pair<int, int>& x,
const pair<int, int>& y) const {
if (abs(a[x.first] - a[x.second]) == abs(a[y.first] - a[y.... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
* Created by IntelliJ IDEA.
* User: piyushd
* Date: 12/11/10
* Time: 2:59 PM
* To change this template use File | Settings | File Templates.
*... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
s << "{";
for (int i = 0; i < t.size(); i++)
s << t[i] ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #Again testing the condition of the server, code by Yijie Xia
import heapq as hq
n=int(input())
s=input()
a=list(map(int,input().split()))
pre=[i-1 for i in range(n)]
nxt=[i+1 for i in range(n)]
free=[1 for i in range(n)]
line=[(abs(a[i]-a[i+1]),i,i+1) for i in range(n-1) if s[i]!=s[i+1]]
hq.heapify(line)
ans=[]
while... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | from heapq import heappush,heappop,heapify
n=int(input())
symbols=input()
skl=list(map(int,input().split()))
LMap=[i-1 for i in range(n+1)]
RMap=[i+1 for i in range(n+1)]
LMap[1],RMap[n]=1,n
h=[]
res=[]
cnt=0
B=symbols.count("B")
N=min(n-B,B)
ind=[True]*(n+1)
for i in range(n-1) :
if symbols[i]!=symbols[i+1] :
... | PYTHON3 |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
long long int n, i;
while (cin >>... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<char> bg;
vector<int> a;
int main() {
int n;
cin >> n;
bg.resize(n);
a.resize(n);
vector<int> next(n, -1);
vector<int> prev(n, -1);
int nG = 0, nB = 0;
for (int i = 0; i < n; ++i) {
cin >> bg[i];
bg[i] == 'B' ? ++nB : ++nG;
}
int k = min(n... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 |
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.util.*;
public class C1{
int[]h;
char[]type;
int[]prev;
int[]next;
int n;
void solve()throws Exception
{
n=nextInt();
typ... | JAVA |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 250000;
bool vis[maxn];
int sk[maxn];
int ll[maxn], rr[maxn];
char s[maxn];
int n;
struct node {
int u, v, val;
};
bool operator<(const node a, const node b) {
if (a.val != b.val) return a.val > b.val;
return a.u > b.u;
}
priority_queue<node> q;
int m... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 3;
struct Node {
int l, r, dif;
Node(int _l = 0, int _r = 0, int _dif = 0) { l = _l, r = _r, dif = _dif; }
bool operator<(const Node &a) const {
if (a.dif == dif) return a.l < l;
return a.dif < dif;
}
};
priority_queue<Node> que;
in... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n, lenans;
int ans[200010][2];
int vis[200010], a[200010], l[200010], r[200010];
char s[200010];
struct point {
int l, r, w;
bool operator<(const point& b) const { return w == b.w ? l > b.l : w > b.w; }
};
priority_queue<point> q;
int main() {
while (~scanf("%d", ... | CPP |
45_C. Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | 2 | 9 | import java.util.*;
public class P045C {
private static class Pair implements Comparable<Pair> {
private int left;
private int right;
private int skillDiff;
public Pair(int left, int right, int skillDiff) {
this.left = left;
this.right = rig... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | import java.util.*;
import java.io.*;
public class Main implements Runnable {
int[] a;
int[] sg;
public void solve() throws IOException {
int N = nextInt(), M = nextInt();
int[] r = new int[M];
int[] l = new int[M];
int[] v = new int[M];
... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | /*
ID: govind.3, GhpS, govindpatel
LANG: JAVA
TASK: Main
*/
import java.io.*;
import java.util.*;
public class Main {
private final int BIT = 30;
private final int MAX = 1000 * 1000;//10^6
private int[] tree = new int[4 * MAX];
private int[] values = new int[MAX];
private void build(int v, ... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class InterestingArray {
static int[] a;
static class SegmentTree {
int [] tree;
int N;
... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const long long base = 1331;
const long long N = 1e5 + 1;
template <typename T>
inline void Cin(T& x) {
char c = getchar();
x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}
template <typename T, typ... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class B {
private static class Query implements Comparable<Query> {
private final int left;
private final int right;
private final int value;
... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
map<int, vector<int> > open, close;
vector<pair<pair<int, int>, int> > query(m);
int a, b, c;
for (int i = 0; i < m; ++i) {
cin >> a >> b >> c;
a--;
b--;
q... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int cL, cR, W, b, n;
struct Itree {
int V[maxn * 4];
void pushdown(int o) {
V[o * 2] |= V[o];
V[o * 2 + 1] |= V[o];
V[o] = 0;
}
void build(int o, int L, int R) {
if (L == R) return;
pushdown(o);
int mid = (L + R) / 2;... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 17;
struct Node {
int l, r, join, meet;
};
Node T[2 * MAX_N];
void update(int l, int r, int q, int i = 1) {
if (r <= T[i].l || l >= T[i].r) return;
if (l <= T[i].l && r >= T[i].r) {
T[i].meet |= q;
return;
}
update(l, r, q, 2 * i);
... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int k[30][100002];
void die() {
printf("NO");
exit(0);
}
int l[100001], r[100001], v[100001], ans[100000];
int main() {
int n, m, i, j, a, b, c;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++) scanf("%d%d%d", l + i, r + i, v + i);
for (i = 0; i < m; i++) {
fo... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const int N = 1e5 + 5;
const int TN = 1 << 18;
const double PI = acos(-1);
int n, m, k;
long long tree[TN], lazy[TN] = {0};
void probagate(int l, int r, int p) {
tree[p] |= lazy[p];
if (l != r) {
lazy[p << 1] |= lazy[p];
lazy[(p << 1)... | CPP |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
impor... | JAVA |
482_B. Interesting Array | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi.
Your task is to find any interesting array of n elements or state that su... | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
for (int(i) = ... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.