标签:algorithm line ida style efi ++ oid getchar freopen
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cmath> 5 #include<cstring> 6 #include<cctype> 7 using namespace std; 8 typedef long long ll; 9 #define enter printf("\n") 10 const int maxn = 1e5 + 5; 11 const int INF = 0x3f3f3f3f; 12 inline ll read() 13 { 14 ll ans = 0; 15 char ch = getchar(), last = ‘ ‘; 16 while(!isdigit(ch)) {last = ch; ch = getchar();} 17 while(isdigit(ch)) 18 { 19 ans = ans * 10 + ch - ‘0‘; ch = getchar(); 20 } 21 if(last == ‘-‘) ans = -ans; 22 return ans; 23 } 24 inline void write(ll x) 25 { 26 if(x < 0) {putchar(‘-‘); x = -x;} 27 if(x == 0) {putchar(‘0‘); return;} 28 int q[100], N = 0; 29 q[1] = 0; 30 while(x) {q[++N] = x % 10; x /= 10;} 31 while(N) {putchar(‘0‘ + q[N]); --N;} 32 } 33 34 int n, l, r; 35 ll a[maxn], sum[maxn]; 36 ll ans = -1e10; 37 38 ll dp[maxn][30]; 39 int size[maxn]; 40 void RMQ(int n) 41 { 42 for(int i = 1; i <= n; ++i) dp[i][0] = sum[i]; 43 for(int j = 1; (1 << j) <= n; ++j) 44 for(int i = 1; i + (1 << j) - 1 <= n; ++i) 45 dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]); 46 int k = 0; 47 for(int i = 1; i <= n; ++i) 48 { 49 if ((1 << k) <= i) k++; 50 size[i] = k - 1; 51 } 52 } 53 ll query(int L, int R) 54 { 55 int k = size[R - L + 1]; 56 return max(dp[L][k], dp[R - (1 << k) + 1][k]); 57 } 58 59 int main() 60 { 61 freopen("holiday.in", "r", stdin); 62 freopen("holiday.out", "w", stdout); 63 n = read(); l = read(); r = read(); 64 for(int i = 1; i <= n; ++i) {a[i] = read(); sum[i] = sum[i - 1] + a[i];} 65 RMQ(n); 66 for(int i = 1; i <= n; ++i) 67 { 68 int L = i + l, R = i + r; 69 if(L > n) break; 70 if(R > n) R = n; 71 ll _ans = query(L, R) - sum[i]; 72 ans = max(ans, _ans); 73 } 74 write(ans); enter; 75 return 0; 76 }
标签:algorithm line ida style efi ++ oid getchar freopen
原文地址:https://www.cnblogs.com/mrclr/p/9057922.html