正文
增加 3 行删除 3 行
14 行未改动1516171819202122234 行未改动282930313233343536373839404125 行未改动14 行未改动1. 当 $n\le k$ 即 $n\le \sqrt s$ 时:询问的区间只有 $O(n^2)$ 种,每种需要 $O(k)$ 的时间求出,则时间复杂度为 $O(n^2k)$,即为 $O(s\sqrt s)$。2. 当 $k\le n$ 即 $k\le \sqrt s$ 时:最坏的情况是每次询问都要 $O(k)$ 回答,此时也只需 $O(qk)$ 即 $O(q\sqrt s)$ 的时间回答。综上,我们可以在 $O(s\sqrt s+q)$ 或 $O(s+q\sqrt s)$ 的时间内解决本问题。4 行未改动#include<bits/stdc++.h>using namespace std;#define ll long longnamespace IO{//by cyffff}const int N=5e5+10;int n,k,q,a[N];ll pr[N];map<ll,ll>ans;int main(){n=read(),k=read(),q=read();for(int i=1;i<=k;i++){int p=(i-1)*n;25 行未改动14 行未改动1516171819202122234 行未改动282930313233343536373839404125 行未改动14 行未改动1. 当 $n\le k$ 即 $n\le \sqrt s$ 时:询问的区间只有 $O(n^2)$ 种,每种需要 $O(k)$ 的时间求出,则时间复杂度为 $O(n^2k)$,即为 $O(s\sqrt s)$。2. 当 $k\le n$ 即 $k\le \sqrt s$ 时:最坏的情况是每次询问都要 $O(k)$ 回答,此时也只需 $O(qk)$ 即 $O(q\sqrt s)$ 的时间回答。综上,我们可以在 $O(s\sqrt s+q)$ 或 $O(s+q\sqrt s)$ 的时间内解决本问题。4 行未改动#include<bits/stdc++.h>using namespace std;#define ll long longnamespace IO{//by cyffff}const int N=5e5+10;int n,k,q,a[N];ll pr[N];map<ll,ll>ans;int main(){n=read(),k=read(),q=read();for(int i=1;i<=k;i++){int p=(i-1)*n;25 行未改动