当前位置:网站首页>(补)双指针专题
(补)双指针专题
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;
}
边栏推荐
- MongoDB 的安装和基本操作
- Getting started with Message Oriented Middleware
- 2022爱分析· 国央企数字化厂商全景报告
- Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
- [combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
- PHP中register_globals参数设置
- 8 cool visual charts to quickly write the visual analysis report that the boss likes to see
- 嵌入式开发:避免开源软件的7个理由
- From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
- 【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
猜你喜欢
One article takes you to understand machine learning
Unreal_DataTable 实现Id自增与设置RowName
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
Mysql 将逗号隔开的属性字段数据由列转行
Visual SLAM algorithms: a survey from 2010 to 2016
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
嵌入式开发:避免开源软件的7个理由
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
MB10M-ASEMI整流桥MB10M
随机推荐
SVN使用规范
Characteristic polynomial and constant coefficient homogeneous linear recurrence
Jmeter线程组功能介绍
PHP二级域名session共享方案
Mongodb installation and basic operation
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
用同花顺炒股开户安全吗?
远程文件包含实操
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
8 tips for effective performance evaluation
How can technology managers quickly improve leadership?
面试之 top k问题
Initial test of scikit learn Library
EditText request focus - EditText request focus
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
面试官:JVM如何分配和回收堆外内存
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵