显示代码纯文本
//周期为2*(a+b) 若a>b+1一个周期包含2a-b个元素否则包含a+1个
#define _CRT_SECURE_NO_WARNINGS
#include<string>
#include<cstdio>
#include<iostream>
using namespace std;
int a, b, l, r, T, sum, num[30],ans;
bool vis[27];
string s;
int main() {
freopen("MrBA1.in", "r", stdin);
freopen("MrBA1.out", "w", stdout);
scanf("%d%d%d%d", &a, &b, &l, &r);
T = (a + b) << 1;
if (a>b + 1)sum = (a << 1) - b;
else sum = a + 1;
if (r - l >= T) { printf("%d", sum); return 0; }
l %= T; r %= T;
l++, r++;
for (int i = 0; i < a; i++)s += char('a' + i);
for (int i = 0; i < b; i++)s += char('a' + a - 1);
if (a > b + 1) {
for (int i = 0; i < b; i++)s += char('a' + i);
for (int i = 0; i < a-b; i++)s += char('a' + a+i);
for (int i = 0; i < b; i++)s += char('a' + a + a-b-1);
for (int i = l - 1; i < r; i++)if (!vis[s[i] - 'a'])vis[s[i] - 'a']++, ans++;
//cout << s<<endl;
printf("%d", ans);
}
else {
for (int i = 0; i < a; i++)s += char('a' + i);
for (int i = 0; i < b; i++)s += char('a' + a + a - 1);
for (int i = l - 1; i < r; i++)if (!vis[s[i] - 'a'])vis[s[i] - 'a']++, ans++;
//cout << s<<endl;
printf("%d", ans);
}
return 0;
}