当前位置:网站首页>(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;
}
边栏推荐
- 《天天数学》连载56:二月二十五日
- How programming apes grow rapidly
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- 于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
- 面试官:JVM如何分配和回收堆外内存
- AcWing 第58 场周赛
- Visual SLAM algorithms: a survey from 2010 to 2016
- Nine ways to define methods in scala- Nine ways to define a method in Scala?
- 切入点表达式
- Unity项目优化案例一
猜你喜欢

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”

Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package

TCP congestion control details | 3 design space

"Remake Apple product UI with Android" (3) - elegant statistical chart

Data driving of appium framework for mobile terminal automated testing

QT串口ui设计和解决显示中文乱码

Détails du contrôle de la congestion TCP | 3. Espace de conception

8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
![[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix](/img/d6/3c21c25f1c750f17aeb871124e80f4.png)
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
随机推荐
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Explore Cassandra's decentralized distributed architecture
斑馬識別成狗,AI犯錯的原因被斯坦福找到了
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
近视:摘镜or配镜?这些问题必须先了解清楚
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
[statement] about searching sogk1997 and finding many web crawler results
[combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
香港理工大学|数据高效的强化学习和网络流量动态的自适应最优周界控制
Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
The difference between calling by value and simulating calling by reference
Golang anonymous function use
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Netease UI automation test exploration: airtest+poco
跟我学企业级flutter项目:简化框架demo参考
Unity项目优化案例一
Nifi from introduction to practice (nanny level tutorial) - flow
线程池执行定时任务