rt,不理解为什么给定序列 a=[1,2,3,⋯,k,0,⋯,0](共 n 个),求 ∑i=1mmaxj=liri(Aj) 都会出错,dalao 求改。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define _Dark_Star exit(0)
#define up(i,x,y) for(int i=x;i<=y;i++)
#define dn(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10|48);}
inline void writeln(int x){write(x),putchar('\n');}
inline void writesp(int x){write(x),putchar(' ');}
const int N = 25;
int n , k , m , a[N] , sum;
signed main(){
n = read() , k = read() , m = read();
up(i,1,k) a[i] = i;
while(m --){
int l = read() , r = read() , max = LONG_LONG_MIN;
up(i,l,r) if(a[i] > max) max = a[i];
sum += max;
}
writeln(sum);
return 0;
}