Bzoj 2743 heoi 2012 Flower Dressing Array

Source: Internet
Author: User

Title: Give a sequence, ask a sequence, there are more than two times the number of colors.


Idea: It looks like an HH necklace.

CODE:


#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1000010using namespace Std;struct ask{int X,y,_id;bool operator < (const ASK &a) Const {return x < a.x;} void Read (int p) {scanf ("%d%d", &x,&y); _id = P;}} Ask[max];int cnt,cols,asks;int fenwick[max];int src[max];int last[max],next[max];int T[MAX];int ans[MAX];inline void Fix (int x,int c) {if (!x) return, for (; x <= cnt; x + = X&-x) fenwick[x] + = C;} inline int getsum (int x) {int re = 0;for (; x; x = x&-x) re + + Fenwick[x];return re;} int main () {cin >> cnt >> cols >> asks;for (int i = 1; I <= cnt; ++i) scanf ("%d", &src[i]); for (int i = 1; I <= CNT; ++i) {if (++t[src[i] = = 2) Fix (i,1), if (Last[src[i]]) next[last[src[i]] [= i;last[src[i]] = i;} for (int i = 1;i <= asks; ++i) Ask[i]. Read (i), sort (ask + 1,ask + asks + 1), ask[0].x = 1;for (int i = 1; I <= asks; ++i) {for (int j = ask[i-1].x; J < ask[ i].x; ++J) {Fix (next[j],-1); Fix (Next[next[j]],1);} ANS[ASK[I]._ID] = getsum (ASK[I].Y);} for (int i = 1; I <= asks; ++i) printf ("%d\n", Ans[i]); return 0;}


Bzoj 2743 heoi 2012 Flower Dressing Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.