이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
int n, q, l[M], r[M], up[M][20];
int t[4 * M], lz[4 * M];
void lazy(int s)
{
t[s * 2] += lz[s];
t[s * 2 + 1] += lz[s];
lz[s * 2] += lz[s];
lz[s * 2 + 1] += lz[s];
lz[s] = 0;
return ;
}
void upd(int s,int l,int r,int u,int v,int val)
{
if(l > v || r < u) return ;
if(u <= l && r <= v) {
t[s] += val;
lz[s] += val;
return ;
}
int mid = (l + r)/2;
if(l != r && lz[s]) lazy(s);
upd(s * 2, l, mid, u, v, val);
upd(s * 2 + 1, mid + 1, r, u, v, val);
t[s] = max(t[s * 2], t[s * 2 + 1]);
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("1.inp","r")) {
freopen("1.inp","r",stdin);
freopen("1.out","w",stdout);
}
#define task ""
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n ;
for(int i = 1;i <= n; i++) {
cin >> l[i] >> r[i];
}
int j = 0;
for(int i = 1;i <= n; i++) {
while(j != n && t[1] <= 1) {
j++;
upd(1,1,n,l[j],r[j],1);
//cout << t[1] << " "<< j <<"\n";
}
if(t[1] > 1) up[i][0] = j;
else up[i][0] = j + 1;
//cout << i << " " << j << "\n";
upd(1,1,n,l[i],r[i],-1);
}
up[n + 1][0] = n + 1;
for(int j = 1;j <= 18; j++) {
for(int i = 1;i <= n + 1; i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
//cout << i << " " << j << " " << up[i][j] << "\n";
}
}
cin >> q;
while(q--) {
int l, r, kq = 0;
cin >> l >> r;
for(int i = 18;i >= 0; i--) {
if(up[l][i] <= r) {
//cout << i << " " << up[l][i] << "\n";
kq += (1 << i);
l = up[l][i];
}
}
cout << kq + 1 << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int32_t main()':
Main.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen("1.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen("1.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(task".out","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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |