A
#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-------------"<<endl
typedef long long ll;
const int maxn = 1e5 + 10;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1010;
int main(){
ll t, l, v, r, L;
scanf("%lld" ,&t);
while(t--){
scanf("%lld%lld%lld%lld", &L, &v, &l, &r);
int num = L / v;
int cnt = (l - 1) / v;
int tem = r / v;
cout << num + cnt - tem<< endl;
}
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
const int N = 10100;
const int INF = 0x3f3f3f3f;
bool vis[N];
int a[N];
int main(){
int n, r;
while(scanf("%d%d", &n, &r) != EOF){
clr(a); clr(vis);
for(int i=1; i<=n; i++) scanf("%d", &a[i]);
bool flag = true;
int cnt = 0;
int dis = 2 * (r - 1) + 1;
int pos = INF;
for(int i=1; i<=n; i++){
if(a[i]){
pos = i; break;
}
}
if(pos > r) flag = false;
else pos = r;
n += (r - 1);
while(pos <= n && pos > 0){
if(a[pos]){
if(vis[pos]){
flag = false; break;
}
else{
cnt++;
vis[pos] = true;
}
}
else{
while(!a[pos]) pos --;
if(vis[pos]){
flag = false; break;
}
else{
cnt++;
vis[pos] = true;
}
}
pos += dis;
}
if(!flag) puts("-1");
else cout << cnt << endl;
}
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 10;
int x[maxn], y[maxn];
char s[11];
int main(){
int t ;
cin >> t;
int l = 0, r = 0;
while (t --){
scanf("%s", s);
int id;
scanf("%d", &id);
if(s[0] == 'L'){
l ++;
x[id] = l;
}
else if(s[0] == 'R'){
r ++;
y[id] = r;
}
else if(s[0] == '?'){
int ans;
if (x[id] != 0) ans = min(l-x[id], x[id]-1+r);
else ans = min(r-y[id], y[id]-1+l);
printf("%d\n", ans);
}
}
return 0;
}
D
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn= 2e5 + 10;
ll a[maxn];
int main(){
ll n, m, k;
cin >> n >> m >> k;
for (int i=n; i>=1; i--) scanf("%lld", &a[i]);
ll temp = 0;
ll ans = 0 , num = 0;
for (int i=1; i<=n; i++){
if (a[i] > k) break;
temp += a[i];
if (temp > k){
num ++;
temp = a[i];
if (num == m) break;
}
ans ++;
}
printf("%lld\n", ans);
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int MOD = 998244353;
char a[maxn], b[maxn];
string aa, bb;
vector<int> z(maxn);
#include<string.h>
int main() {
int n, m, ans = 0;
cin >> n >> m >> aa >> bb;
reverse(aa.begin(), aa.end());
reverse(bb.begin(), bb.end());
strcpy(a, aa.c_str());
strcpy(b, bb.c_str());
int N = max(n, m), s = 1;
for(int i=0; i<N; i++){
z[i] = a[i] == '1' ? s : 0;
z[i] = (z[i] + (i > 0 ? z[i - 1] : 0)) % MOD;
s <<= 1;
s %= MOD;
}
for(int i=0; i<m; i++){
ans += b[i] == '1' ? z[i] : 0;
ans %= MOD;
}
cout << ans << endl;
return 0;
}