diff --git a/src/10/10/P6006.cpp b/src/10/10/P6006.cpp new file mode 100644 index 0000000..6295990 --- /dev/null +++ b/src/10/10/P6006.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +using ll = int64_t; + +const ll maxn = 5e3+5; +ll n,q, dp[maxn][maxn], a[maxn]; + +struct T{ + const static ll of = 2e6+3; + ll v[4*ll(1e6+5)]; // 注意限制的大小要*2 + inline ll&operator[](const ll n){ + return v[n+of]; + } +}tot; + +std::vector used; + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n>>q; + for(ll i=1;i<=n;i++){ + std::cin>>a[i]; + } + + for(ll i=n-2;i>=1;i--){ // 注意循环顺序!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + for(ll j:used)tot[j]=0; // 注意清空耗时 + used.clear(); + tot[a[i+1]]++; + used.emplace_back(a[i+1]); + for(ll j=i+2;j<=n;j++){ + dp[i][j] = tot[-(a[i]+a[j])]; + // printf("before dp[%lld][%lld]=%lld\n",i,j,dp[i][j]); + dp[i][j] += dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1]; + tot[a[j]]++; + used.emplace_back(a[j]); + // printf("after dp[%lld][%lld]=%lld\n",i,j,dp[i][j]); + } + } + + while(q--){ + ll a,b; + std::cin>>a>>b; + std::cout<