답안 #615304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615304 2022-07-31T08:21:42 Z 조영욱(#8494) Ants and Sugar (JOI22_sugar) C++17
0 / 100
312 ms 15808 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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 179 ms 11392 KB Output is correct
3 Incorrect 312 ms 15808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -