이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353
void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s))
{
freopen((s + ".in").c_str(), "r", stdin);
if (s != "test1")
freopen((s + ".out").c_str(), "w", stdout);
}
}
class segment_tree_lazy
{
struct item
{
int sum, add, update;
};
item single(int i)
{
return { i,0,-1 };
}
item merge(item x, item y)
{
item ans;
ans.sum = x.sum + y.sum;
ans.add = 0;
ans.update = -1;
return ans;
}
vector<item> tree;
vector<item>A;
int height;
item neutral = { 0,0,-1 };
void push(int i, int tl, int tr)
{
if (tree[i].update != -1)
{
tree[i].update += tree[i].add;
tree[i].add = 0;
tree[i].sum = tree[i].update * (tr - tl + 1);
if (tl != tr)
{
tree[2 * i + 1].add = 0; tree[2 * i + 1].update = tree[i].update;
tree[2 * i + 2].add = 0; tree[2 * i + 2].update = tree[i].update;
}
tree[i].update = 0;
}
else
{
tree[i].sum += tree[i].add * (tr - tl + 1);
if (tl != tr)
{
tree[2 * i + 1].add += tree[i].add;
tree[2 * i + 2].add += tree[i].add;
}
tree[i].add = 0;
}
}
public:void build(vi& B)
{
int n = B.size();
height = log2(n - 1) + 1;
A.rsz(n);
tree.rsz((1 << height + 1) - 1);
F0R(i, n)A[i] = single(B[i]);
A.rsz(1 << height, neutral);
build(A, 0, 0, (1 << height) - 1);
}
void build(vector<item>& A, int v, int tl, int tr)
{
if (tl == tr)
tree[v] = A[tl];
else
{
int mid = (tl + tr) / 2;
build(A, 2 * v + 1, tl, mid);
build(A, 2 * v + 2, mid + 1, tr);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
public:int query(int l, int r)
{
return query(0, 0, (1 << height) - 1, l, r).sum;
}
item query(int v, int tl, int tr, int l, int r)
{
if (r<tl || l>tr)return neutral;
push(v, tl, tr);
if (l <= tl && r >= tr)
{
return tree[v];
}
int mid = (tl + tr) / 2;
return merge(query(2 * v + 1, tl, mid, l, r), query(2 * v + 2, mid + 1, tr, l, r));
}
public:void update(int l, int r, int val)
{
update(0, 0, (1 << height) - 1, l, r, val);
}
void update(int v, int tl, int tr, int l, int r, int val)
{
push(v, tl, tr);
if (tl > r || tr < l)return;
if (tl >= l && tr <= r)
{
tree[v].update = val;
tree[v].add = 0;
push(v, tl, tr);
//tree[v].sum = ((ll)tr - tl + 1) * val;
}
else
{
int mid = (tl + tr) / 2;
update(2 * v + 1, tl, mid, l, r, val);
update(2 * v + 2, mid + 1, tr, l, r, val);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
public:void add(int l, int r, int val)
{
add(0, 0, (1 << height) - 1, l, r, val);
}
void add(int v, int tl, int tr, int l, int r, int val)
{
push(v, tl, tr);
if (tl > r || tr < l)return;
if (tl >= l && tr <= r)
{
tree[v].add += val;
push(v, tl, tr);
//tree[v].sum += ((ll)tr - tl + 1) * val;
}
else
{
int mid = (tl + tr) / 2;
add(2 * v + 1, tl, mid, l, r, val);
add(2 * v + 2, mid + 1, tr, l, r, val);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
public:int get(int x)
{
push(0, 0, (1 << height) - 1);
if (tree[0].sum < x)return -1;
return get(0, 0, (1 << height) - 1, x);
}
int get(int i, int tl, int tr, int x)
{
push(i, tl, tr);
if (tl == tr)return tl;
int mid = (tl + tr) / 2;
push(2 * i, tl, mid);
push(2 * i + 1, mid + 1, tr);
if (x > tree[2 * i + 1].sum)
return get(2 * i + 2, mid + 1, tr, x - tree[2 * i + 1].sum);
return get(2 * i + 1, tl, mid, x);
}
};
#ifndef arwaeystoamneg
//#include "elephants.h"
#endif
const int MAX = 100004;//100005;
int n, l[MAX], r[MAX], prefix[MAX];
vi a;
int GetBestPosition(int N, int C, int R, int* K, int* S, int* E)
{
n = N;
a.rsz(n - 1);
F0R(i, n - 1)
{
a[i] = (K[i] > R);
}
F0R(i, C)l[i] = S[i], r[i] = E[i];
segment_tree_lazy t;
vi temp(MAX);
F0R(i, n + 1)temp[i] = 1;
t.build(temp);
vpi qu;
F0R(i, C)
{
int le = t.get(l[i] + 1), ri = t.get(r[i] + 2) - 1;
t.update(le + 1, ri, 0);
qu.pb({ le,ri });
}
//trav(x, qu)cout << x.f << " " << x.s << endl;
F0R(i, sz(a))prefix[i + 1] = prefix[i] + a[i];
pii ans = { -inf,-inf };
F0R(i, n)
{
int c = 0;
trav(x, qu)
{
if (x.f > i || x.s < i)continue;
if (prefix[x.f]==prefix[x.s])c++;
}
if (ans.f < c)ans = { c,i };
}
return ans.s;
}
#ifdef arwaeystoamneg
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
int main() {
setIO("test1");
int tmp;
/* Set input and output buffering */
char* inbuf, * outbuf;
inbuf = (char*)malloc(inbuf_len * sizeof(char));
outbuf = (char*)malloc(outbuf_len * sizeof(char));
tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
assert(tmp == 0);
tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
assert(tmp == 0);
int N, C, R;
int* K, * S, * E;
tmp = scanf("%d %d %d", &N, &C, &R);
assert(tmp == 3);
K = (int*)malloc((N - 1) * sizeof(int));
S = (int*)malloc(C * sizeof(int));
E = (int*)malloc(C * sizeof(int));
int i;
for (i = 0; i < N - 1; i++) {
tmp = scanf("%d", &K[i]);
assert(tmp == 1);
}
for (i = 0; i < C; i++) {
tmp = scanf("%d %d", &S[i], &E[i]);
assert(tmp == 2);
}
printf("%d\n", GetBestPosition(N, C, R, K, S, E));
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
tournament.cpp: In member function 'void segment_tree_lazy::build(vi&)':
tournament.cpp:105:24: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
105 | tree.rsz((1 << height + 1) - 1);
| ~~~~~~~^~~
tournament.cpp: In function 'void setIO(std::string)':
tournament.cpp:48:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
48 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tournament.cpp:50:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
50 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |