ãå ¨ä½ã«è¶³ããã®ã¯é£ããããã足ãå¤ãå¥éæã£ã¦ããã¨ããã¹ãã«ï¼ï¼ï¼ã
åé¡æ¦è¦
以ä¸ã® åã®ã¯ã¨ãªã«çããã
- ã¯ã¨ãªã¿ã¤ã 1ï¼æ°ãã«è¦ç´ 0 ãæ¿å ¥ããï¼éè¤ãããï¼
- ã¯ã¨ãªã¿ã¤ã 2ï¼ãã§ã«æ¿å ¥ããã¦ãããã¹ã¦ã®è¦ç´ ã« ã足ã
- ã¯ã¨ãªã¿ã¤ã 3ï¼ãã§ã«æ¿å ¥ããã¦ããè¦ç´ ã®ãã¡ã 以ä¸ã§ãããã®ããã¹ã¦åé¤ãããã®åæ°ãçãã
å¶ç´
èãããã¨
3 種é¡ã®ã¯ã¨ãªæä½ã®ãã¡ã大å¤ãªã®ã¯ã¯ã¨ãªã¿ã¤ã 2ããã¹ã¦ã®è¦ç´ ã« ã足ããã ããããæç´ã«ããã¨ãå ¨ä½ã®è¨ç®éã ã«ãªã£ã¦ãã¾ãã®ã ã
ä¸æ¹ãã¯ã¨ãªã¿ã¤ã 3 ã«é¢ãã¦ã¯ããã»ã©å¤ãªãã¼ã¿æ§é ã使ããªãéããè¨ç®éçã«ã¯å¤§ä¸å¤«ããããããã¯ã¨ãªå ¨ä½ãéãã¦æ¿å ¥ãããè¦ç´ ã®åæ°ãæ大 åãªã®ã§ãåé¤ãããè¦ç´ ã®åæ°ãæ大㧠åã§ãããåé¤æä½ãååéããã¼ã¿æ§é ãç¨ããã°ãã¯ã¨ãªã¿ã¤ã 3 ã®è¨ç®éã¯å¤§ä¸å¤«ã
ã
ã¯ã¨ãªã¿ã¤ã 2ããã¹ã¦ã®è¦ç´ ã« ã足ããã«å¯¾å¦ãã
ãã®ããã«ãå ¨ã¦ã®è¦ç´ ã«ä¸å¾ã« ã足ããã¨ããå ´é¢ã§ããã使ããã¯ããããããã¯
å®éã«å
¨ã¦ã®è¦ç´ ã« ã足ãã®ã§ã¯ãªãããå¾ã§è¶³ããã¨ããæå³ãè¾¼ããå¤æ°ï¼offset
ã¨ããï¼ãå¥éæã£ã¦ãã
ã¨ããæ¹æ³ã ãé 延è©ä¾¡ãªã©ã¨ãå¼ã¶ãã¨ãããããããç¨ããã¨ããµã³ãã« 1 ã¯æ¬¡ã®ããã«è§£éã§ããã
ã¯ã¨ãª | ã¯ã¨ãªå¾ã®éå | offset |
åè |
---|---|---|---|
1 | {0} | 0 | |
2, 15 | {0} | 15 | 15 ã¯éåã®è¦ç´ ã«è¶³ããã« offset ã«è¶³ã |
1 | {0, -15} | 15 | offset ã 15 ãªã®ã§ã0 ã§ãªã -15 ãæ¿å
¥ãã |
3, 10 | {-15} | 15 | offset ã 15 ãªã®ã§ã10 - 15 = -5 以ä¸ã®æ°ãåé¤ãã |
2, 20 | {-15} | 35 | offset ã« 20 ã足ã |
3, 20 | {} | 35 | offset ã 35 ãªã®ã§ã20 - 35 = -15 以ä¸ã®æ°ãåé¤ãã |
ãã®è¡¨ã®ä¾ã ã¨ãéåã®ãµã¤ãºãå°ããã®ã§å¤æ° offset
ã®ããããã¿ããã¾ããªããããããéåã®ãµã¤ãºã大ãããªã£ãã¨ããã¯ã¨ãªã¿ã¤ã 2 ã®å¦çãåã«ãoffset += T
ãã§æ¸ã¾ããããããã«ãªããã¨ã¯ãè¨ç®éçã«çµ¶å¤§ãªã¡ãªããã¨ãªãã
ä»ã®ã¯ã¨ãªã¿ã¤ããå«ãã¦ã¾ã¨ããã¨ã
- ã¯ã¨ãªã¿ã¤ã 1ï¼éåã« 0 ãæ¿å
¥ããã®ã§ã¯ãªãã
-offset
ãæ¿å ¥ãã - ã¯ã¨ãªã¿ã¤ã 2ï¼
offset += T
ã¨ãã - ã¯ã¨ãªã¿ã¤ã 3ï¼éåãã
H
以ä¸ã®å¤ãåé¤ããã®ã§ã¯ãªããH - offset
以ä¸ã®å¤ãåé¤ãã
ã¨ããããã«ä¿®æ£ããã
ã
ã¯ã¨ãªã¿ã¤ã 3 ã«ã¤ãã¦
æå¾ã«ãã¯ã¨ãªã¿ã¤ã 3ãéåãã H - offset
以ä¸ã®å¤ãåé¤ããããå®ç¾ããæ¹æ³ãèãããããããããªæããã£ã¦
- éåãå®ç¾ãããã¼ã¿æ§é ã¨ãã¦
priority_queue
ã使ããéåã®æ大å¤ãH - offset
以ä¸ã§ããéããåé¤ãã - éåãå®ç¾ãããã¼ã¿æ§é ã¨ãã¦
queue
ã使ããæãå¤ãææã«æ¿å ¥ãããè¦ç´ ãH - offset
以ä¸ã§ããéãããããåé¤ãã
ãªã©ãèãããããä¸ã®ã³ã¼ãã§ã¯å¾è ãæ¡ç¨ãããã¨ã«ããããã®å ´åã®è¨ç®éã¯ãã¯ã¨ãªå ¨ä½ãéã㦠ã¨ãªãã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; int main() { long long Q, query_type, T, H; cin >> Q; long long offset = 0; // 伸ã³ãå queue<long long> que; while (Q--) { cin >> query_type; if (query_type == 1) { que.push(-offset); } else if (query_type == 2) { cin >> T; offset += T; } else { cin >> H; long long res = 0; while (!que.empty() && que.front() + offset >= H) { res++; que.pop(); } cout << res << endl; } } }