本人是学习时长两年半的蒟蒻,天天TLE
一个芯出衣的OIer
$$百度一下$$
$$洛谷$$
$$.$$
$$不要CTJ$$
$$图论编辑器$$
$$实用工具小合集$$
代码区:
倍增(st表)
#include<bits/stdc++.h>
using namespace std;
int st[100005][23],lg[100005];
int ask(int l,int r){
int k = lg[r-l+1];
return max(st[l][k],st[r-(1<<k)+1][k]);
}
signed main(){
int n,m;cin>>n>>m;
lg[0] = -1;
for(int i =1;i<=n;i++){
lg[i] = lg[i>>1]+1;
cin>>st[i][0];
}
for(int j=1;(1<<j)<=n;j++){
for(int i =1;i+(1<<j)-1<=n;i++){
st[i][j] = max(st[i][j-1],st[i+(1<<j-1)][j-1]);
}
}
while(m--){
int l,r;cin>>l>>r;
cout<<ask(l,r)<<"\n";
}
}
链表
#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node * next;
};
node * p, *head=NULL,*q;
void print(){
p=head;
while(p!=NULL){
cout<<p->data<<" ";
p=p->next;
}
cout<<"\n";
}
int k,x,y;
void del(){
cin>>y;
if(y==1){
p=head;
head=p->next;
delete p;
}
else{
q=head;
for(int i =1;i<y-1;i++){
q=q->next;
}
p=q->next;
q->next=p->next;
delete p;
}
print();
}
void insert(){
cin>>k>>x;
q=head;
p=new node;
p->data=x;
if(k==1){
p->next=head;
head=p;
}
else{
for(int i =1;i<k-1;i++){
q=q->next;
}
p->next=q->next;
q->next=p;
}
print();
}
int main(){
int n;cin>>n;
for(int i =1;i<=n;i++){
int w;cin>>w;
p=new node;
p->data=w;
p->next=head;
head=p;
}
insert();
del();
}
二分查找
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],x,q;
int main(){
cin>>n;
for(int i =1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
cin>>q;
while(q--){
cin>>x;
int l = 1,r = n;
while(l<=r){
int mid = (l+r)>>1;
if(a[mid]>=x) r = mid-1;
else l = mid+1;
}
if(a[r+1]==x) cout<<r+1<<"\n";
else cout<<"-1\n";
}
}
Oops!
You are not assigned to this contest.
$$2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2^{2}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} = ?$$