当前位置:网站首页>(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;
}
边栏推荐
- Mixlab编辑团队招募队友啦~~
- One article takes you to understand machine learning
- Data driving of appium framework for mobile terminal automated testing
- 记一次jar包冲突解决过程
- 线程池执行定时任务
- 【LeetCode】94. Middle order traversal of binary tree
- SVN使用规范
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
- 高等数学(第七版)同济大学 习题2-1 个人解答
- PHP中register_globals参数设置
猜你喜欢
Visual SLAM algorithms: a survey from 2010 to 2016
Deep understanding of grouping sets statements in SQL
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
QT串口ui设计和解决显示中文乱码
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
跟我学企业级flutter项目:简化框架demo参考
2022爱分析· 国央企数字化厂商全景报告
QT serial port UI design and solution to display Chinese garbled code
How to use AAB to APK and APK to AAB of Google play apps on the shelves
随机推荐
手机注册股票开户安全吗 开户需要钱吗
TCP congestion control details | 3 design space
Is it safe to open an account with flush?
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
深入理解 SQL 中的 Grouping Sets 语句
Is it safe to open an account with tongdaxin?
[web security] - [SQL injection] - error detection injection
Learn from me about the enterprise flutter project: simplified framework demo reference
Mongodb installation and basic operation
PHP CI(CodeIgniter)log级别设置
Threejs Part 2: vertex concept, geometry structure
程序猿如何快速成长
Explore Netease's large-scale automated testing solutions see here see here
高等数学(第七版)同济大学 习题2-1 个人解答
Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation
2022爱分析· 国央企数字化厂商全景报告
疫情常态化大背景下,关于远程办公的思考|社区征文
8 tips for effective performance evaluation
Remote file contains actual operation
QT serial port UI design and solution to display Chinese garbled code