Submission #62805668
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <vector>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <functional>
#include <stack>
#include <map>
#include <random>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
typedef long long LL;
typedef std::pair<int,int> PII;
typedef std::pair<LL,LL> PLL;
#define INF 0x3f3f3f3f
#define rep(i,l,r) for(auto i(l);i<=(r);++i)
#define per(i,r,l) for(auto i(r);i>=(l);--i)
#define rpp(i,l,r) for(auto i(l);i<(r);++i)
#define ppr(i,r,l) for(auto i(r);i>(l);--i)
#define lowbit(x) ((x)&-(x))
#define ls(p) ((p)<<1)
#define rs(p) ((p)<<1|1)
template<typename T>inline T min(T a,T b){return a<b?a:b;}
template<typename T>inline T max(T a,T b){return a>b?a:b;}
const int N = 200010;
const int M = 5000010;
const int mod = 1'000'000'007;
// char *p1,*p2,buf[100000];
// #define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
template<typename T>inline void read(T &x){
x=0;
char ch=getchar(),f=0;
while(ch<'0' || ch>'9'){f=(ch=='-');ch=getchar();if(ch==EOF){break;}}
while(ch<='9' && ch>='0'){x=x*10+(ch^48);ch=getchar();}
f?x=-x:0;
}
template<std::size_t N>inline void read(char (&s)[N]){
char *p=s,ch=getchar();
while(isspace(ch)){ch=getchar();if(ch==EOF){break;}}
while(!isspace(ch) && std::size_t(p-s+1)<N){*p=ch;++p;ch=getchar();}
while(*p && std::size_t(p-s)<N){*p=0;++p;}
}
inline void read(char &ch){ch=getchar();while(isspace(ch)){ch=getchar();if(ch==EOF){break;}}}
template<typename T,typename... Args>inline void read(T &x,Args&... args){read(x);read(args...);}
template<typename T>inline void write(T x){
char s[40],*t=s;
for(;1;++t,x/=10){
if(x<0){putchar('-');x=-x;}
if(x<10){*t=x^48;break;}
*t=(x%10)^48;
}
while(t>=s){putchar(*t);--t;}
}
inline void write(char *s){while(*s){putchar(*s);++s;}}
inline void write(const char *s){while(*s){putchar(*s);++s;}}
inline void write(char ch){putchar(ch);}
template<typename T,typename... Args>void write(T x,Args ...args){write(x);write(args...);}
template<typename T>inline void writen(T x){write(x,'\n');}
template<typename T,typename... Args>void writen(T x,Args ...args){write(x,'\n');writen(args...);}
template<typename T>inline void writel(T x){write(x,'\n');}
template<typename T,typename... Args>void writel(T x,Args ...args){write(x,' ');writel(args...);}
int n,q;
int a[N];
int t[N];
int ans[N];
struct node{
int r,x,id;
};
std::vector<node> v;
std::vector<PII> p;
auto update = [](int x,int d){
while(x<=n){
t[x]=max(t[x],d);
x+=lowbit(x);
}
};
auto sum = [](int x){
int res=0;
while(x){
res=max(res,t[x]);
x-=lowbit(x);
}
return res;
};
int main(){
read(n,q);
rep(i,1,n){read(a[i]);p.push_back({a[i],i});}
rep(i,1,q){
node t;
read(t.r,t.x);
t.id=i;
v.emplace_back(t);
}
std::sort(v.begin(),v.end(),[](node a,node b){return a.x<b.x;});
std::sort(p.begin(),p.end(),[](PII a,PII b){return a.first>b.first || (a.first==b.first && a.second<b.second);});
for(auto i : v){
while(!p.empty() && p.back().first<=i.x){
auto x=p.back();p.pop_back();
update(x.second,sum(x.second)+1);
}
ans[i.id]=sum(i.r);
}
rep(i,1,q){writen(ans[i]);}
return 0;
}
/*
-std=c++14
-Wall -O2 -static
-Wall -O2 -fsanitize=address,undefined
LHY qingchunkeai,shanliangdafang,wengrouxianhui,meilidongren,chenyuluoyan,biyuexiuhua
*/
Submission Info
Submission Time |
|
Task |
F - Prefix LIS Query |
User |
Xr0805 |
Language |
C++ 20 (gcc 12.2) |
Score |
500 |
Code Size |
3578 Byte |
Status |
AC |
Exec Time |
62 ms |
Memory |
10988 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 03_random3_09.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
1 ms |
3504 KB |
00_sample_01.txt |
AC |
1 ms |
3512 KB |
01_random_00.txt |
AC |
1 ms |
3568 KB |
01_random_01.txt |
AC |
24 ms |
6564 KB |
01_random_02.txt |
AC |
28 ms |
6308 KB |
01_random_03.txt |
AC |
22 ms |
5924 KB |
01_random_04.txt |
AC |
27 ms |
6620 KB |
01_random_05.txt |
AC |
29 ms |
7120 KB |
01_random_06.txt |
AC |
62 ms |
10728 KB |
01_random_07.txt |
AC |
62 ms |
10760 KB |
01_random_08.txt |
AC |
61 ms |
10716 KB |
01_random_09.txt |
AC |
62 ms |
10764 KB |
01_random_10.txt |
AC |
62 ms |
10756 KB |
01_random_11.txt |
AC |
62 ms |
10792 KB |
01_random_12.txt |
AC |
62 ms |
10800 KB |
01_random_13.txt |
AC |
62 ms |
10744 KB |
01_random_14.txt |
AC |
62 ms |
10772 KB |
02_random2_00.txt |
AC |
60 ms |
10828 KB |
02_random2_01.txt |
AC |
61 ms |
10740 KB |
02_random2_02.txt |
AC |
61 ms |
10736 KB |
02_random2_03.txt |
AC |
62 ms |
10884 KB |
02_random2_04.txt |
AC |
62 ms |
10796 KB |
03_random3_00.txt |
AC |
49 ms |
10900 KB |
03_random3_01.txt |
AC |
45 ms |
10988 KB |
03_random3_02.txt |
AC |
49 ms |
10776 KB |
03_random3_03.txt |
AC |
45 ms |
10812 KB |
03_random3_04.txt |
AC |
52 ms |
10720 KB |
03_random3_05.txt |
AC |
46 ms |
10720 KB |
03_random3_06.txt |
AC |
55 ms |
10744 KB |
03_random3_07.txt |
AC |
46 ms |
10780 KB |
03_random3_08.txt |
AC |
54 ms |
10960 KB |
03_random3_09.txt |
AC |
49 ms |
10780 KB |
04_handmade_00.txt |
AC |
35 ms |
10856 KB |
04_handmade_01.txt |
AC |
42 ms |
10980 KB |
04_handmade_02.txt |
AC |
31 ms |
10700 KB |
04_handmade_03.txt |
AC |
29 ms |
10744 KB |
04_handmade_04.txt |
AC |
41 ms |
10712 KB |