Vijos P1881 閃爍的繁星 (自己加強了一下。。),vijosp1881

來源:互聯網
上載者:User

Vijos P1881 閃爍的繁星 (自己加強了一下。。),vijosp1881

如果每一次查詢的不是整個長度,而是[x, y]這個區間。。閑來無事自己寫了一下,感覺是對的,這樣就變成了合并區間。


#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <queue>#include <algorithm>#define mem(f) memset(f,0,sizeof(f))#define M 100005#define mod 1000000007#define lson o<<1, l, m#define rson o<<1|1, m+1, rusing namespace std;typedef long long LL;const int MAX = 0x3f3f3f3f;const int maxn = 200005;int mx_three(int a, int b, int c) {    return max(a, max(b, c));}int n, q, c, x, y, b[maxn];struct C {    int mx, lx, rx;} a[maxn<<2];void build(int o, int l, int r) {    a[o].lx = a[o].mx = a[o].rx = 1;    if(l == r) return;    int m = (l+r) >> 1;    build(lson);    build(rson);}C query(int o, int l, int r) {    if(x <= l && r <= y) return a[o];    int m = (l+r) >> 1, len = r-l+1;    if(y <= m) return query(lson);    if(m < x ) return query(rson);    C s, s1, s2;    s1 = query(lson);    s2 = query(rson);    s.lx = s1.lx;    s.rx = s2.rx;    if(b[m] != b[m+1]) {        if(s.lx == len-(len>>1)) s.lx += s2.lx;        if(s.rx == len>>1) s.rx += s1.rx;        s.mx = mx_three(s1.mx, s2.mx, s1.rx+s2.lx);    } else s.mx = max(s1.mx, s2.mx);    return s;}void update(int o, int l, int r) {    if(l == r) {        b[c] ^= 1;        return;    }    int m = (l+r) >> 1;    if(c <= m) update(lson);    else update(rson);    int len = r-l+1, L = o<<1, R = o<<1|1;    a[o].lx = a[L].lx;    a[o].rx = a[R].rx;    if(b[m] != b[m+1]) {        a[o].mx = mx_three(a[L].mx, a[R].mx, a[L].rx+a[R].lx);        if(a[o].lx == len-(len>>1)) a[o].lx += a[R].lx;        if(a[o].rx == len>>1) a[o].rx += a[L].rx;    } else a[o].mx = max(a[L].mx, a[R].mx);}int main(){    scanf("%d%d", &n, &q);    build(1, 1, n);    while(q--) {        int rr;        scanf("%d", &rr);        if(rr == 2) {            scanf("%d", &c);            update(1, 1, n);        } else {            scanf("%d%d", &x, &y);            printf("%d\n", query(1, 1, n).mx);        }    }    return 0;}


在讀繁星閃爍著,這句詩時,你受到了什啟發

“繁星”在太空中閃爍著,這就是他們美麗的生命;閃爍著的繁星,構成了黑夜中一個光亮的、引人遐思的世界。因為繁星的存在,黑夜才不可怕!
 
冰心《繁星》的賞析,要一下這段

表現“愛”的精神的總領。從中我們可看出《繁星》這部作品的意蘊。天空閃爍的那些或明或暗的繁星,就同一個個美麗的生命,充滿了活力,也帶給人以無限的遐想。這是繁星的天空,也是一片心靈的天空。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.