Codeforces Global Round 6.E题

给除n个数,每个数需要a[i]个,产生一个数需要一个单位的时间,再给出q个成就,成就的奖励是一个数字,如果两个成就相同,那么先得到成就的奖励就会失效,求每个成就达到之后还需要的时间
用map,直接查找当前成就以前是否得到过,得到过就让以前的成就失效,再让当前成就替代,每次更新ans值输出

//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
#define love ios::sync_with_stdio(false) //用爱加速
#define debug() puts("what the fuck") //吐槽debug
#define stophere() system("pause")
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN= 1e6+10;
double PI=3.1415926535898;
typedef long long ll;
//优先队列结构体
//struct number_______x {    int a,b;    bool operator < (const number_______x &x) {        return a > x.a;  //从小到大排序   }}
int a[MAXN];
int main() {
    int n;
    ll ans = 0;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) {scanf("%d",&a[i]);;ans+=a[i];}
    int q;
    cin >> q;
    map<pair<int,int>,int> mmp;
    while(q--) {
        int s,t,u;
        scanf("%d%d%d",&s,&t,&u);
        if(mmp[{s,t}] > 0) {
            a[mmp[{s,t}]] ++;
            if(a[mmp[{s,t}]] > 0) ans ++;
            mmp[{s,t}] = 0;
        }
        if(u) {
            mmp[{s,t}] = u;
            a[u]--;
            if(a[u] >= 0) ans--;
        }
    //debug();
        printf("%lld\n",ans);
    }
    system("pause");
}

我终于有了热血。。。算是一点点吧,一点点也好。。

猜你喜欢

转载自www.cnblogs.com/ASLHZXY/p/12105271.html