码迷,mamicode.com
首页 > 其他好文 > 详细

cogs 2569. [東方] 博丽灵梦 梦想妙珠

时间:2017-08-10 22:35:56      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:ons   logs   freopen   his   query   return   main   blog   algorithm   

二次联通门 : cogs 2569. [東方] 博丽灵梦 梦想妙珠

 

 

 

 

/*
    cogs 2569. [東方] 博丽灵梦 梦想妙珠

    莫队水过。。
    
    好久没一遍AC了。。
    
    卡线上榜2333 
*/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

char Buf[100000001], *buf = Buf;
int BUF = 100000001;

void read (int &now)
{
    for (now = 0; !isdigit (*buf); ++ buf);
    for (; isdigit (*buf); now = now * 10 + *buf - 0, ++ buf);
}

#define Max 100000

int belong[Max];

struct Data
{
    int l, r, c, Id;
    
    bool operator < (const Data &now) const
    {
        return belong[this->l] == belong[now.l] ? this->r < now.r : belong[this->l] < belong[now.l];
    }
};

int count[Max << 1 | 1];

Data query[Max | 1];
int number[Max | 1];

int Answer[Max];

#define Cogs

int main (int argc, char *argv[])
{

#ifdef Cogs

    freopen ("mengxiangmiaozhu.in", "r", stdin);
    freopen ("mengxiangmiaozhu.out", "w", stdout);
    fread (buf, 1, BUF, stdin);
    
#endif
    
    int N, M;
    read (N);
    register int i;
    int x;
    
    int K_Size = sqrt (N);
        
    for (i = 1; i <= N; ++ i)
        read (number[i]), belong[i] = (i + 1) / K_Size;
    
    read (M);
    
    for (i = 1; i <= M; ++ i)
    {
        read (query[i].l);
        read (query[i].r);
        read (query[i].c);
    }
    
    for (i = 1; i <= M; ++ i)
        query[i].Id = i;
        
    std :: sort (query + 1, query + 1 + M);
    
    int l = 1, r = 0;
    
    for (i = 1; i <= M; ++ i)
    {
        
        for (; l < query[i].l; -- count[number[l]], ++ l);
        for (; l > query[i].l; -- l, ++ count[number[l]]);
        for (; r < query[i].r; ++ r, ++ count[number[r]]);
        for (; r > query[i].r; -- count[number[r]], -- r);
        
        Answer[query[i].Id] = count[query[i].c];
    } 
    
    for (i = 1; i <= M; ++ i)
        printf ("%d\n", Answer[i]);
        
    return 0;
}

 

cogs 2569. [東方] 博丽灵梦 梦想妙珠

标签:ons   logs   freopen   his   query   return   main   blog   algorithm   

原文地址:http://www.cnblogs.com/ZlycerQan/p/7341304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!