Submission #615155

# Submission time Handle Problem Language Result Execution time Memory
615155 2022-07-31T07:14:44 Z 조영욱(#8494) Ants and Sugar (JOI22_sugar) C++17
0 / 100
229 ms 15652 KB
#include <bits/stdc++.h>
using namespace std;

int q,l;
typedef pair<int,int> P;
set<P> s;

int main() {
    scanf("%d %d",&q,&l);
    long long ret=0;
    for(int i=0;i<q;i++) {
        int t,x,a;
        scanf("%d %d %d",&t,&x,&a);
        if (t==1) {
            auto iter=s.lower_bound(P(x,-1));
            if (iter!=s.end()&&(*iter).first==x) {
                int val=(*iter).second+a;
                s.erase(iter);
                s.insert(P(x,val));
            }
            else {
                s.insert(P(x,a));
            }
        }
        else {
            auto iter=s.lower_bound(P(x-l,-1));
            vector<P> er;
            while (1) {
                if (iter==s.end()) {
                    break;
                }
                if (a==0) {
                    break;
                }
                P now=(*iter);
                er.push_back(now);
                if (a<now.second) {
                    s.insert(P(now.first,now.second-a));
                    ret+=a;
                    break;
                }
                ret+=now.second;
                a-=now.second;
                iter++;
            }
            for(int j=0;j<er.size();j++) {
                s.erase(er[j]);
            }
        }
        printf("%lld\n",ret);
    }
    return 0;
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             for(int j=0;j<er.size();j++) {
      |                         ~^~~~~~~~~~
sugar.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&q,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
sugar.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d %d %d",&t,&x,&a);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 174 ms 11424 KB Output is correct
3 Incorrect 229 ms 15652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -