当前位置:网站首页>(Supplement) double pointer topic
(Supplement) double pointer topic
2022-07-03 16:28: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;}// Its lowest 1 And behind it 0 The value of composition
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;}// Its lowest 1 And behind it 0 The value of composition
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;}// Its lowest 1 And behind it 0 The value of composition
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;
}
边栏推荐
- (补)双指针专题
- 线程池执行定时任务
- Characteristic polynomial and constant coefficient homogeneous linear recurrence
- 架构实战营 - 第 6 期 毕业总结
- Construction practice camp - graduation summary of phase 6
- SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Custom plug-in construction and use of QT plug-in
- Cocos Creator 2.x 自动打包(构建 + 编译)
- 面试官:JVM如何分配和回收堆外内存
猜你喜欢
[list to map] collectors Tomap syntax sharing (case practice)
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
探索Cassandra的去中心化分布式架构
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
Multithread 02 thread join
[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
Record a jar package conflict resolution process
TCP congestion control details | 3 design space
The difference between calling by value and simulating calling by reference
随机推荐
Mongodb installation and basic operation
First knowledge of database
Basis of target detection (IOU)
相同切入点的抽取
PHP secondary domain name session sharing scheme
疫情常态化大背景下,关于远程办公的思考|社区征文
pycharm错Error updating package list: connect timed out
Interviewer: how does the JVM allocate and recycle off heap memory
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
The mixlab editing team is recruiting teammates~~
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
[web security] - [SQL injection] - error detection injection
Extraction of the same pointcut
Golang 匿名函数使用
用同花顺炒股开户安全吗?
Expression of request header in different countries and languages
Top k questions of interview
PHP中register_globals参数设置
Netease UI automation test exploration: airtest+poco
Alibaba P8 painstakingly sorted it out. Summary of APP UI automated testing ideas. Check it out