当前位置:网站首页>(补)双指针专题
(补)双指针专题
2022-07-03 16:25:00 【leimingzeOuO】

M - Letters
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){
return (a%mod+mod)%mod;}
LL lowbit(LL x){
return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {
LL ans = 1; while(b){
if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,m;
const int N=2e5+10;
int a[N],b[N];
int s[N];
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
for(int i=1;i<=m;i++)cin>>b[i];
for(int i=1;i<=m;i++)
{
int l=0,r=n;
while(l<r)
{
int mid=l+r+1>>1;
if(s[mid]<=b[i])l=mid;
else r=mid-1;
}
if(s[l]!=b[i])
cout<<l+1<<' '<<b[i]-s[l]<<endl;
else cout<<l<<' '<<s[l]-s[l-1]<<endl;
}
}
signed main()
{
io;
//cin>>_;
//while(_--)
solve();
return 0;
}
N - Kirill And The Game
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){
return (a%mod+mod)%mod;}
LL lowbit(LL x){
return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {
LL ans = 1; while(b){
if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int l,r,x,y,k;
void solve()
{
cin>>l>>r>>x>>y>>k;
for(int i=x;i<=y;i++)
{
int left=l,right=r;
while(left<right)
{
int mid=left+right>>1;
if(mid>=k*i)right=mid;
else left=mid+1;
}
if(i*k==left)
{
cout<<"YES"<<endl;
return;
}
}
cout<<"NO"<<endl;
}
signed main()
{
io;
//cin>>_;
//while(_--)
solve();
return 0;
}
O - Sereja and Dima
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n;
cin>>n;
vector<int>v;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
v.push_back(x);
}
int a=0,b=0;
int l=0,r=v.size()-1;
while(l<=r)
{
if(l<=r&&v[l]<v[r])a+=v[r--];
else if(l<=r)a+=v[l++];
if(l<=r&&v[l]<v[r])b+=v[r--];
else if(l<=r)b+=v[l++];
}
cout<<a<<' '<<b<<endl;
return 0;
}
P - Alice, Bob and Chocolate
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){
return (a%mod+mod)%mod;}
LL lowbit(LL x){
return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {
LL ans = 1; while(b){
if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=1e5+10;
int a[N];
int s[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
vector<PII>v;
for(int i=1;i<=n;i++)
{
int x=s[i],y=s[n]-s[i];
if(x-a[i]>y||y-a[i+1]>x)continue;
else v.pb({
i,n-i});
}
int m=v.size()-1;
cout<<v[m].x<<' '<<v[m].y<<endl;
return;
}
signed main()
{
io;
//cin>>_;
//while(_--)
solve();
return 0;
}
边栏推荐
- Multithread 02 thread join
- Embedded development: seven reasons to avoid open source software
- 无心剑中译泰戈尔《漂鸟集(1~10)》
- [combinatorics] non descending path problem (outline of non descending path problem | basic model of non descending path problem | non descending path problem expansion model 1 non origin starting poi
- 在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
- [statement] about searching sogk1997 and finding many web crawler results
- Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
- Mysql 单表字段重复数据取最新一条sql语句
- [combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
- 面试官:JVM如何分配和回收堆外内存
猜你喜欢

How to use AAB to APK and APK to AAB of Google play apps on the shelves

TCP拥塞控制详解 | 3. 设计空间

MB10M-ASEMI整流桥MB10M

初试scikit-learn库

The mixlab editing team is recruiting teammates~~

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
![[statement] about searching sogk1997 and finding many web crawler results](/img/1a/8ed3ca0030ea227adcd95e8b306aca.png)
[statement] about searching sogk1997 and finding many web crawler results

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

Unreal_DataTable 实现Id自增与设置RowName

Mongodb installation and basic operation
随机推荐
Cocos Creator 2. X automatic packaging (build + compile)
六月 致 -.-- -..- -
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
远程办公之大家一同实现合作编辑资料和开发文档 | 社区征文
[combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
Remote file contains actual operation
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
Getting started with Message Oriented Middleware
"Remake Apple product UI with Android" (3) - elegant statistical chart
Nifi from introduction to practice (nanny level tutorial) - flow
8 tips for effective performance evaluation
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
线程池执行定时任务
Uploads labs range (with source code analysis) (under update)
How can technology managers quickly improve leadership?
Myopia: take off or match glasses? These problems must be understood clearly first
How to initialize views when loading through storyboards- How is view initialized when loaded via a storyboard?
Visual SLAM algorithms: a survey from 2010 to 2016
Mongodb installation and basic operation