题目链接
 
 
示例1
输入
复制
4 1 2 1 1 4 5 2 2 2 3 4
输出
复制
10
说明
在第4格放出水流后,水流会流向第3格,由于第3格高度比第4格低,所以水流继续向左流向第2格,因为平地水流只能流2格,所以到达第2格后水流停止,收获的小麦数量为1 + 4 + 5 = 10
示例2
输入
复制
5 2 2 1 1 4 5 1 2 2 3 3 4 4 3
输出
复制
9 6
题意:
从左到右非递减的台阶上每个格子长着ai个小麦,小麦遇到水就会被采集,一个格子的水在同一高度最多可以向外扩散k-1个格子 ,如果高度改变将重新计算扩散(水只会往低处流),q次询问,每次在一个格子上放水,能收集到多少小麦。
思路:
先用前缀和将小麦求一遍,之后在每次输入台阶高度的时候就进行预处理水能流的情况(水只会往左流),这样可以避免在询问的时候进行多次计算从而超时:
评价:
非常非常非常简单的一题,但是我不知道什么情况赛时超时之后就一直优化不出来,而且发现代码能力显著下降了,是最近松懈了,反思,重努力找回状态
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod1 =998244353;
const ll mod2 =1e9+7;
const ll hash_num = 3e9+9;
ll n,m,ca, k, p,ans;
ll arr[N],brr[N],crr[N];
 ll h[N],ne[N],e[N],w[N],book[N],idx;
ll hh[N];
//ll book[N];
void solve()
{
    ll q;
      cin >> n >> q >> k;
    for(int  i = 1; i <= n; i ++ ){
        cin >> w[i];
        w[i] += w[i - 1];
    }
    int last = 1;
    cin >> h[1];
    hh[1] = 1;
    last = 1;
    rep(i,2,n){
        cin >> h[i];
        if(h[i] != h[i - 1]){
            last = i - 1;
        }
        if(h[max(i - k + 1, ll(1))] == h[i]){
            hh[i] = i - k + 1;
        }
        else{
            hh[i] = hh[last];
        }
    }
    while(q--)
    {
        int ip;
        cin >> ip;
        cout << w[ip]-w[hh[ip]-1]<<endl;
    }
}
int main()
{
   IOS;
   ll _;
    _=1;
    //scanf("%lld",&_);
    //cin>>_;
    ca=1;
    while(_--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}



















