Submission #61826112


Source Code Expand

Copy
/*
Start:
End:
Time used:
……
…………
DON'T GET STUCK ON ONE APPROACH!!!
*/
#include <bits/stdc++.h>//
#define re register//
#define rep(i,a,b) for (re int i = (a);i <= (b); ++i)
#define debug(x) cout << #x << '=',print(x),putchar(' ')
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define pi pair<int,int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
using namespace std;//
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/*
Start: 
End: 
Time used: 
「責任を負う人の話は、あなたと話したことがありますよね」 
「当時の私はまだわからないけど……今は理解できるようになった」 
「大人としての責務。そして、その延長線上にある、あなたの選択」 
「それに代表されるアイデアもあります」 
「だから、先生」 
「信じられる大人のあなたなら、この歪んだ変形の終点とは、違う結果……そこにつながる選択肢……きっとあなたは見つけることができます」
DON'T GET STUCK ON ONE APPROACH!!!
*/
#include <bits/stdc++.h>//喵内~
#define re register//喵内~
#define rep(i,a,b) for (re int i = (a);i <= (b); ++i)
#define debug(x) cout << #x << '=',print(x),putchar(' ')
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define pi pair<int,int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
using namespace std;//喵内~
inline ll read(){
    ll s = 0,f = 1;char c = getchar();
    while (!isdigit(c)){if (c == '-')f = -1;c = getchar();}
    while (isdigit(c)){s = (s<<3) + (s<<1) + (c ^ 48);c = getchar();}
    return s * f;
}//喵内~
void print(__int128 x){if (x < 0) {putchar('-'),print(-x);return ;}if (x >= 10) print(x / 10);putchar(x % 10 + 48);}//喵内~
const int Mod = 1e9 + 7;//喵内~要填数字哟~
//const int Mod = 998244353;//喵内~要填数字哟~
const ll INF = 0x3f3f3f3f;
const int N = 5e5 + 5;//喵内~要填数字哟~
ll qpow(ll x,ll y){
   ll res = 1;
    for (;y;y >>= 1,x = x * x % Mod) if (y & 1) res = res * x % Mod;
    return res;
}
int n;
int tree[N << 2],lazy[N << 2];
void pushup(int rt){tree[rt] = max(tree[rt << 1],tree[rt << 1 | 1]);}
void build(int rt,int l,int r){
    if (l == r){tree[rt] = l; return ;}
    int mid = l + r >> 1;
    build(rt << 1,l,mid);
    build(rt << 1 | 1,mid + 1,r);
    pushup(rt);
}
void pushdown(int rt){
    if (lazy[rt]){
        lazy[rt << 1] += lazy[rt];
        lazy[rt << 1 | 1] += lazy[rt];
        tree[rt << 1] += lazy[rt];
        tree[rt << 1 | 1] += lazy[rt];
        lazy[rt] = 0;
    }
}
void add(int rt,int l,int r,int x,int y,int val){
    if (l > y || r < x) return ;
    if (l >= x && r <= y){
        tree[rt] += val;
        lazy[rt] += val;
        return ;
    }
    pushdown(rt);
    int mid = l + r >> 1;
    add(rt << 1,l,mid,x,y,val);
    add(rt << 1 | 1,mid + 1,r,x,y,val);
    pushup(rt);
}
int rfind(int rt,int l,int r,int x){
    if (l == r) return l;
    pushdown(rt);
    int mid = l + r >> 1;
    if (tree[rt << 1] > x) return rfind(rt << 1,l,mid,x);
    else return rfind(rt << 1 | 1,mid + 1,r,x);
}
int query(int rt,int l,int r,int pos){
    if (l == r) return tree[rt];
    int mid = l + r >> 1;
    pushdown(rt);
    if (pos <= mid) return query(rt << 1,l,mid,pos);
    else return query(rt << 1 | 1,mid + 1,r,pos);
}
signed main(){
    n = read();
    build(1,1,N - 1);
    for (int i = 1;i <= n;++i){
        int l = read(),r = read();
        int L = rfind(1,1,N - 1,l - 1),R = rfind(1,1,N - 1,r) - 1;
        if (L > R) continue;
        add(1,1,N - 1,L,R,1);
    }

    int q = read();
    while (q--){
        int x = read();
        cout << query(1,1,N - 1,x) << endl;
    }
    return 0;
}//喵内~
/*
What's wrong with my code?
1. 小数据?特殊数据?如 n = 1?
2. 最小值,最大值取多少?是否会溢出?
3. 初始值有没有赋值?有没有建树?
4. 数组大小?是否越界?
5. 思考暴力的时候,考虑是否可能是多个连续段?或者是个数不确定无法暴力?
6. 进行详细的分类讨论?
7. 选择的区间是否可以为空?

Trick:
1. 连通 通常带有特殊性质
2. LIS 有另一种求法
3. Brovuka?

About implementation skills:
1. 全局变量多用长变量名,而局部变量,临时变量,和函数传递的参数使用短变量名。
2. 大模拟尽量遵循:怎么方便怎么写。
3. 对于一些数据很小的需要维护的量并且需要大量讨论时,可以考虑把数组拆掉换成变量。
4. 写成多个函数。
*/

Submission Info

Submission Time
Task F - Rated Range
User FlamingBlade
Language C++ 20 (gcc 12.2)
Score 525
Code Size 4222 Byte
Status AC
Exec Time 556 ms
Memory 11872 KB

Compile Error

Main.cpp: In function ‘void build(int, int, int)’:
Main.cpp:43:17: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   43 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function ‘void add(int, int, int, int, int, int)’:
Main.cpp:65:17: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   65 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function ‘int rfind(int, int, int, int)’:
Main.cpp:73:17: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   73 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function ‘int query(int, int, int, int)’:
Main.cpp:79:17: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   79 |     int mid = l + r >> 1;
      |               ~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 5 ms 7784 KB
00_sample_01.txt AC 5 ms 7644 KB
00_sample_02.txt AC 5 ms 8268 KB
01_test_00.txt AC 9 ms 11576 KB
01_test_01.txt AC 8 ms 11636 KB
01_test_02.txt AC 7 ms 11484 KB
01_test_03.txt AC 6 ms 9828 KB
01_test_04.txt AC 330 ms 11728 KB
01_test_05.txt AC 556 ms 11684 KB
01_test_06.txt AC 329 ms 11612 KB
01_test_07.txt AC 556 ms 11812 KB
01_test_08.txt AC 382 ms 11732 KB
01_test_09.txt AC 555 ms 11872 KB
01_test_10.txt AC 267 ms 11728 KB
01_test_11.txt AC 555 ms 11644 KB
01_test_12.txt AC 396 ms 11712 KB
01_test_13.txt AC 550 ms 11652 KB
01_test_14.txt AC 246 ms 11644 KB
01_test_15.txt AC 548 ms 11728 KB
01_test_16.txt AC 45 ms 11724 KB
01_test_17.txt AC 555 ms 11684 KB
01_test_18.txt AC 334 ms 11648 KB
01_test_19.txt AC 551 ms 11684 KB
01_test_20.txt AC 405 ms 11652 KB
01_test_21.txt AC 416 ms 11708 KB
01_test_22.txt AC 403 ms 9232 KB
01_test_23.txt AC 405 ms 8820 KB
01_test_24.txt AC 503 ms 11644 KB
01_test_25.txt AC 495 ms 11680 KB
01_test_26.txt AC 503 ms 11644 KB
01_test_27.txt AC 506 ms 11684 KB
01_test_28.txt AC 5 ms 7816 KB
01_test_29.txt AC 5 ms 7560 KB
01_test_30.txt AC 5 ms 7656 KB
01_test_31.txt AC 5 ms 7656 KB
01_test_32.txt AC 5 ms 7576 KB


2025-03-05 (Wed)
20:38:41 +00:00