zoukankan      html  css  js  c++  java
  • codeforces 869 E. The Untended Antiquity(树状数组)

    题目链接:http://codeforces.com/contest/869/problem/E

    题解:这题是挺好想到solution的但是不太好写,由于题目的特殊要求每个矩形不会重贴所以只要这两个点最内抱着他们的是同一个矩形就行了。就是最近抱汉她们的矩形是同一个就行了。有一种方法挺好的主要是数据是大多数随机的,所以可以考虑hash一下rand一下每个点的赋值然后求前缀和相同就是满足条件的,这里可以用一下2维德树状数组做一下。seed尽量大点这样失败的概率也就小点官方题解有详细的概率数据可以参考一下。然后就这样了........

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <map>
    using namespace std;
    const int M = 2500 + 10;
    typedef unsigned long long ll;
    pair<ll , ll> mmp[M][M];
    pair<ll , ll> nub[M][M];
    void add(int x , int y , pair<int , int> num) {
        for(int i = x ; i <= 2501 ; i += (i & (-i))) {
            for(int j = y ; j <= 2501 ; j += (j & (-j))) {
                nub[i][j].first += num.first;
                nub[i][j].second += num.second;
            }
        }
    }
    pair<ll , ll> query(int x , int y) {
        pair<ll , ll> res;
        for(int i = x ; i ; i -= (i & (-i))) {
            for(int j = y ; j ; j -= (j & (-j))) {
                res.first += nub[i][j].first;
                res.second += nub[i][j].second;
            }
        }
        return res;
    }
    int main() {
        int n , m , q;
        int t , r1 , c1 , r2 , c2;
        scanf("%d%d%d" , &n , &m , &q);
        srand((1 << 31));
        pair<ll , ll> ad , rd;
        while(q--) {
            scanf("%d%d%d%d%d" , &t , &r1 , &c1 , &r2 , &c2);
            if(t == 1) {
                ad.first = mmp[r1][c1].first = rand();
                ad.second = mmp[r1][c1].second = rand();
                rd.first = -ad.first;
                rd.second = -ad.second;
                add(r1 , c1 , ad);
                add(r2 + 1 , c1 , rd);
                add(r1 , c2 + 1 , rd);
                add(r2 + 1 , c2 + 1 , ad);
            }
            if(t == 2) {
                rd = mmp[r1][c1];
                ad.first = -rd.first;
                ad.second = -rd.second;
                add(r1 , c1 , ad);
                add(r2 + 1 , c1 , rd);
                add(r1 , c2 + 1 , rd);
                add(r2 + 1 , c2 + 1 , ad);
                mmp[r1][c1] = make_pair(0 , 0);
            }
            if(t == 3) {
                ad = query(r1 , c1);
                rd = query(r2 , c2);
                if(ad == rd) printf("Yes
    ");
                else printf("No
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    SpringSecurity配置
    SpringBoot整合Mybatis
    springboot整合JDBC
    SpringBoot的WEB流程
    List&TreeSet实现斗地主发牌及牌序
    SpringBoot第一个程序
    项目错误总结2021.4.21
    Spring整合Mybatis
    学习——构建民航业知识图谱并实现语义查询的
    新闻文本分类——词云可视化
  • 原文地址:https://www.cnblogs.com/TnT2333333/p/7647962.html
Copyright © 2011-2022 走看看