生活随笔
收集整理的這篇文章主要介紹了
教主的魔法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門:https://www.luogu.org/problemnew/show/P2801
這道題當時在考場上時間不夠了w,沒有來得及碼線段樹,也沒有去敲分塊w,只是去搞個n^2暴力。。。
結果,悲哀的事情是,我的快讀寫錯了,然后樣例還過了。。。。。自己造的數據還是兩位數的都讀進去了w。。。
然后考完試之后的我依舊不想寫分塊or線段樹。。。。
于是乎,嘿嘿嘿:
我們看一下數據范圍,Q?≤?3000,一開始的身高?≤?1000,還不強制在線。
這意味著什么?
這意味著我們可以搞一些事情。
由于我們的詢問只有3000個,那么這個序列就被這詢問的3000個左端點和3000個右端點分成了6000段(還是6001段。。。。。這不重要)。
然后對于每一段我們用s[i][j]?記錄第i段權值 ≥?j 的有多少個.
對于每一段區間都枚舉一遍所有的詢問,修改肯定是整段區間一起修改,打個標記就可以了,查詢的時候把詢問減掉標記查一下權值。
時間復雜度是O(2Q(Q+1000))。
#define B cout << "BreakPoint" << endl;
#define O(x) cout << #x << " " << x << endl;
#define O_(x) cout << #x << " " << x << " ";
#define Msz(x) cout << "Sizeof " << #x << " " << sizeof(x)/1024/1024 << " MB" << endl;
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#define LL long long
#define inf 1000000009
#define N 1000000
using namespace std;
inline int read() {int s = 0,w = 1;char ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-')w = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {s = s * 10 + ch - '0';ch = getchar();}return s * w;
}
void file() {//srand(time(NULL)+rand());freopen("qwq.in","r",stdin);freopen("qwq.out","w",stdout);
}
int n,Q,k,a[N],f[N],len,m,s[6005][1005],tag[N],ans[N],res;
struct query {int opt,l,r,v,id;
} e[N];
void init() {n = read(),Q = read();for(int i = 1; i <= n; i++) {a[i] = read();}for(int i = 1,c; i <= Q; i++) {c = 0;while(c != 'M' && c != 'A')c = getchar();e[i].opt = (c == 'A');e[i].l = read();e[i].r = read();e[i].v = read();f[++res] = e[i].l;f[++res] = e[i].r + 1;if(c == 'A') {e[i].id = ++k;}}return ;
}
void solve() {sort(f + 1,f + res + 1);m = unique(f + 1,f + res + 1) - f - 1;f[m + 1] = n + 1;for(int i = 1; i <= Q; i++) {e[i].l = lower_bound(f + 1,f + m + 1,e[i].l) - f;e[i].r = upper_bound(f + 1,f + m + 1,e[i].r) - f - 1;}for(int i = 1; i <= m; i++) {for(int j = f[i]; j < f[i + 1]; j++) {s[i][a[j]]++;}for(int j = 1000; j; j--) {s[i][j] += s[i][j + 1];}}for(int i = 1; i <= m; i++) {for(int j = 1; j <= Q; j++) {if(e[j].l <= i && i <= e[j].r) {if(!e[j].opt) tag[i] += e[j].v;else {if(e[j].v - tag[i] <= 0) ans[e[j].id] += f[i + 1] - f[i];else if(e[j].v - tag[i] <= 1000) ans[e[j].id] += s[i][e[j].v - tag[i]];}}}}for(int i = 1; i <= k; i++) {printf("%d\n",ans[i]);}return ;
}
int main() {init();solve();return 0;
}
轉載于:https://www.cnblogs.com/excellent-zzy/p/10992031.html
總結
以上是生活随笔為你收集整理的教主的魔法的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。